Reputation: 1620
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 following 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 %>
Upvotes: 2
Views: 6285
Reputation: 54762
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 %>
Upvotes: 4