Bojan Mihelac
2006-Feb-02 13:45 UTC
[Rails] What is best way to show only records belonging to logged user?
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
2006-Feb-02 13:50 UTC
[Rails] What is best way to show only records belonging to logged user?
@user.records.find(blabla) mikkel On 2/2/06, Bojan Mihelac <lists@mihelac.org> 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? > > 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 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060202/dc7d5b98/attachment.html
Alex Young
2006-Feb-02 13:50 UTC
[Rails] What is best way to show only records belonging to logged user?
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? -- Alex
Bojan Mihelac
2006-Feb-02 19:04 UTC
[Rails] What is best way to show only records belonging to logged user?
Alex Young wrote:> 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? >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