PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 8, 2022

[FIXED] How to show posts onto a static page

 July 08, 2022     posts, ruby-on-rails, static     No comments   

Issue

I have created a image uploading type website. I can login and upload images and it shows perfectly.

But I want to create a landing page for users who are not logged in and can see few images on the landing page.

And whenever someone uploads an image, it should update on the landing page as well. Kinda like in descending order.

I tried to create a static page on top of the yield in the views/layouts/application.html.haml but it didn't work because whenever I'll upload something, it will show me the landing page then on the bottom, the form.

Can anyone tell me how to accomplish this?


Solution

Assuming your root route points to your landing page,

root 'welcome#index'

In controller, fetch the image records you want to show on the landing page,

class WelcomeController < ApplicationController

  def index
    @images = Image.last(10)
  end

end

Use them in views,

- @images.each do |image|
  # put them in img tag


Answered By - Nitish Parkar
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing