jmazzi
1
Right now, im doing this in my controller:
@message = Message.find(params[:id],:conditions => [“user_id = ?”,
@session[‘user’].id])
Is there a way to do with in models them self so i dont have to pass in
a user_id condition for all finds, deletes, etc?
jmazzi
2
On Oct 27, 2006, at 8:16 AM, jmazzi wrote:
Right now, im doing this in my controller:
@message = Message.find(params[:id],:conditions => [“user_id = ?”,
@session[‘user’].id])
Is there a way to do with in models them self so i dont have to
pass in
a user_id condition for all finds, deletes, etc?
@session[‘user’].messages.find(params[:id])
–
– Tom M., CTO
– Engine Y., Ruby on Rails Hosting
– Reliability, Ease of Use, Scalability
– (866) 518-YARD (9273)
jmazzi
3
On Fri, 27 Oct 2006, jmazzi wrote:
Right now, im doing this in my controller:
@message = Message.find(params[:id],:conditions => [“user_id = ?”,
@session[‘user’].id])
Is there a way to do with in models them self so i dont have to pass in
a user_id condition for all finds, deletes, etc?
class User < ActiveRecord::Base
has_many :messages
end
Then you can do the following once you have a valid user.
@user.messages
jmazzi
4
Can that be used in the message contoller?
@user.messages