You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
flyerhzm edited this page Aug 13, 2010
·
3 revisions
Please go to http://rails-bestpractices.com/posts/25-move-code-into-model
Before:
<% if current_user && (current_user == @post.user ||
@post.editors.include?(current_user)) %>
<%= link_to 'Edit this post', edit_post_url(@post) %>
<% end %>
After:
<% if @post.editable_by?(current_user)) %>
<%= link_to 'Edit this post', edit_post_url(@post) %>
<% end %>
class Post < ActiveRecord::Base
def editable_by?(user)
user && (user == self.user || self.editors.include?(user))
end
end