on the main layout for my controller, i need a list of users - each with
their own link to a lists of tasks that they have been assigned.
i did have a line inside the .rhtml file that found all the users, but
i’m guessing this is probably the wrong place to put them. i’m new to
ruby and rails, so i still struggle a little with the MVC concept.
I would think that putting the find command in your model would be the
best place.
On Tue, 2006-04-25 at 20:32 +0200, Josh K. wrote:
on the main layout for my controller, i need a list of users - each with
their own link to a lists of tasks that they have been assigned.
i did have a line inside the .rhtml file that found all the users, but
i’m guessing this is probably the wrong place to put them. i’m new to
ruby and rails, so i still struggle a little with the MVC concept.
Charlie B.
www.recentrambles.com
Charlie B. wrote:
I would think that putting the find command in your model would be the
best place.
when putting something in the model, does it have to be within a “def
action_name” block, or can it be defined anywhere?
Yes, I would create a method in the model to find the list of users. I
would then call the method from within my controller. Here’s a little
sudo code.
Model:
def find_users
put your sql or find statement here
end
Controller
@users = User.find_users
Charlie bowman
www.recentrambles.com
On Apr 25, 2006, at 03:20 PM, Charlie B. wrote:
@users = User.find_users
Quick correction here: if you want to use the method in this manner,
where you don’t have an existing instance of the User class that you
are performing the method on, you have to define the method as a
class method, not an instance method, like so:
def self.find_users
…
end
Btw, this is exactly what I recommend doing, especially in those
cases where the kind of find you want to perform is one you will do
in more than one location and the complexity of the find is more than
you can do with a simple dynamic finder:
User.find_all_by_firstname_and_lastname(params[:firstname], params
[:lastname])
-Brian