Ok so i have been starting to get used to rails 3 over the past few days and have got a project in the works to test things out on. Is it possible to do the fo开发者_运维问答llowing or what would you suggest is the best way to only allow post authors to edit their posts.
<% if post.author_id == current_user.id %>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
<% end %>
Recommendation: Don't compare id
s - compare objects.
<% if post.author == current_user %>
Optional: Consider using a plugin (only if necessary) like cancan
to make it even more descriptive.
<% if can? :edit, post %>
精彩评论