ruby on rails - How to make a user can only read his post? -
i beginner of rails. have created new app, , scaffold post, , install devise & cancan. tutorials found this:
def initialize(user) user ||= user.new if user.admin? can :manage, article else can :read, article end end
i don't want users can reading posts of my_own, want every user can reading posts. how can that? hope finish sample because foolish guy. lot!
you can pass in hash conditions e.g.
def initialize(user) user ||= user.new if user.admin? can :manage, article else can :manage, article, user_id: user.id can :read, article end end
ruby-on-rails devise cancan
No comments:
Post a Comment