Forum: Ruby on Rails What is best way to show only records belonging to logged us

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.
Bojan Mihelac (Guest)
on 2006-02-02 14:47
(Received via mailing list)
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 Mihelac

--
Bojan Mihelac
Informatika Mihelac, Bojan Mihelac s.p.  |  www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org
Mikkel Bruun (Guest)
on 2006-02-02 14:50
(Received via mailing list)
@user.records.find(blabla)

mikkel
Alex Young (Guest)
on 2006-02-02 14:53
(Received via mailing list)
Bojan Mihelac 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?
Bojan Mihelac (Guest)
on 2006-02-02 20:05
(Received via mailing list)
Alex Young wrote:
>
Yes, thanks for the answer.

Bojan

--
Bojan Mihelac
Informatika Mihelac, Bojan Mihelac s.p.  |  www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org
This topic is locked and can not be replied to.