Ruby on Rails
Sunday, March 6, 2016
On Sun, Mar 6, 2016 at 4:59 PM, Hitesh Sancheti <lists@ruby-forum.com> wrote:
Hello everyone, I just started off with RoR and had a question.
I wanted to link my 'Show All Posts' to my allposts.html.erb which will
display all the posts that are created but I am having difficulty in
doing so. Do I need to define this in routes.rb file. I just want to
display all posts when that link is clicked.
<ul class="nav navbar-nav">
<li><%= link_to "New Post", new_post_path %></li>
<li><%= link_to "Show All Posts", '#' %></li>
<li><a href="#contact">Contact</a></li>
</ul>
allposts.html.erb contents
<% @posts.each do |post| %>
<h2><%= post.title %></h2>
<p><%= post.body%></p> <br>
<%= link_to "Show Posts", post %>
<% end %>
This is normally Colin's answer, but I suggest you first work a complete tutorial such as Michael Hartl's http://railstutorial.org/book, which is free to read online.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t_Vj-pnchHMMnz8tub6roXPDEZWu2OmtNkQhqtAC%2BubUg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment