partial a _preview in posts index.html.erb


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. partial a _preview in posts/index.html.erb
  2. -------------
  3. way_1
  4.  
  5. code @ index.html.erb
  6.  
  7. <%= render :partial => "posts/preview", :collection => @posts, :as => :post %>
  8.  
  9.  
  10. code @ _preview.html.erb
  11.  
  12. <% div_for post do %>
  13. <h2><%= link_to_unless_current h(post.title), post %></h2>
  14. <%= truncate(post.body, :length => 300) %> <stule class="read_more"><%= link_to_unless_current h("read more"), post %></style> <br /><br />
  15. <% end %>
  16. -------------
  17.  
  18. way_2
  19.  
  20. code @ index.html.erb
  21.  
  22. <%= render :partial => "preview" %>
  23.  
  24. code @ _preview.html.erb
  25.  
  26. <% for post in @posts do %>
  27. <% div_for post do %>
  28. <h2><%= link_to_unless_current h(post.title), post %></h2>
  29. <%= truncate(post.body, :length => 300) %> <stule class="read_more"><%= link_to_unless_current h("read more"), post %></style> <br /><br />
  30. <% end %>
  31. <% end %>
  32.  
  33. -------------

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.