What is best way to show only records belonging to logged us

Hi all,

What is best way to show only records belonging to logged user? I
understand that it is better to handle this in model and not controller.
I am thinking of intercepting find methods in model and add clause
something like “WHERE id_user = #{user_id}”. I would like to hear if you
would do it likewise and if yes is it better to hack find_by_sql() or
find() method?

thanks in advance,
Bojan M.


Bojan M.
Informatika Mihelac, Bojan M. s.p. | www.informatikamihelac.com
→ tools, scripts, tricks from our code lab: http://source.mihelac.org

@user.records.find(blabla)

mikkel

Bojan M. wrote:

Hi all,

What is best way to show only records belonging to logged user? I
understand that it is better to handle this in model and not controller.
I am thinking of intercepting find methods in model and add clause
something like “WHERE id_user = #{user_id}”. I would like to hear if you
would do it likewise and if yes is it better to hack find_by_sql() or
find() method?
Surely a belongs_to relationship on the records is all you need?

Alex Y. wrote:

Yes, thanks for the answer.

Bojan


Bojan M.
Informatika Mihelac, Bojan M. s.p. | www.informatikamihelac.com
→ tools, scripts, tricks from our code lab: http://source.mihelac.org