Forum: Ruby on Rails where does logic for the layout go?

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.
66d1d0df01e4bbb82674a353ea68d6ee?d=identicon&s=25 Josh Kieschnick (jjkiesch)
on 2006-04-25 20:32
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.
89d967359903c639d31e4cad4569f537?d=identicon&s=25 Charlie Bowman (Guest)
on 2006-04-25 20:52
(Received via mailing list)
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 Kieschnick 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 Bowman
www.recentrambles.com
66d1d0df01e4bbb82674a353ea68d6ee?d=identicon&s=25 Josh Kieschnick (jjkiesch)
on 2006-04-25 21:06
Charlie Bowman 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?
89d967359903c639d31e4cad4569f537?d=identicon&s=25 Charlie Bowman (Guest)
on 2006-04-25 21:23
(Received via mailing list)
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
7c4087d053eb02d099a17d91ba5e33b5?d=identicon&s=25 Brian Hughes (Guest)
on 2006-04-25 21:33
(Received via mailing list)
On Apr 25, 2006, at 03:20 PM, Charlie Bowman 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
66d1d0df01e4bbb82674a353ea68d6ee?d=identicon&s=25 Josh Kieschnick (jjkiesch)
on 2006-04-25 21:48
so for
>> @users = User.find_users
if it is not inside a "def" block of code, does that make it accessible
to all of the actions in that controller?
This topic is locked and can not be replied to.