Owner based authorization / passing arguments to filters

Hi all,
I’m new to rails so this may be obvious, but…
I want to implement a simple owner-based authentication system. Every
(there are different types of item) in the system has a field owner_id
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]

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
that is being checked, or will I need to put it in the session?

All help is greatly appreciated.



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…