Forum: Ruby on Rails owner based authorization / passing arguments to filters.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
aidanf (Guest)
on 2005-11-24 19:47
(Received via mailing list)
Hi all,
I'm new to rails so this may be obvious, but...
I want to implement a simple owner-based authentication system. Every
item
(there are different types of item) in the system has a field owner_id
which
is a foreign key to the user table. A user has permission to edit an
item if
they own the item.

So to check if a user owns an item I can do something like:

def owner?(item)
  item.user_id == session[:user_id]
end

Is there an easy way to enforce this across the whole system? Can I
implement this as a filter? Can I pass an argument to a filter i.e. the
item
that is being checked, or will I need to put it in the session?

All help is greatly appreciated.

thanks,

AF
pertl (Guest)
on 2005-11-24 19:51
(Received via mailing list)
Hi folks,

Do you know if I can use <%= error_messages_for ... %> without having a
specific activerecord object? just dump some custom messages which
belong to
no specific model object...

regards
Peter
This topic is locked and can not be replied to.