Ruby on Rails Sunday, March 6, 2016

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 %>

--
Posted via http://www.ruby-forum.com/.

--
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/029eca5e594f285e04690612bd378750%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment