I have such a problem, I just started to learn RoR.
I have data in the database (Blog Name, Title, Content). I need to select the last 5 entries, how to implement it? What to write and where? In the controller? What exactly to write?
This is the homepage view, the second link should go to the page with the selected five entries.
<div id="head"><h2 align="center">Музыкальный блог musicasfreedom</h2> <p id="come"> <%= link_to "Войти", posts_path %> <br> <%= link_to "Показать пять последних",posts_path(@index1)%> def index1 @index1 = Post.limit(5) respond_to do |format| format.html # index.html.erb format.json { render json: @posts } end end def index @posts = Post.all respond_to do |format| format.html # index.html.erb format.json { render json: @posts } end end
Now I have ALL entries on both links ...