You''ll hear more than one point of view on this issue, here''s
mine:
Storing business logic that is specific to the data a model represents
is what models are for. Do you find that there are complex things you
do with your models, over and over in many places? Factor out that
code and drop it onto the model, adding it as a method. Then you can
just ask the model for the answer rather than slogging through it each
time.
I''d recommend taking a look at some actual source code to see how
models are used. Technoweenie''s Beast is a good example... in
http://svn.techno-weenie.net/projects/beast/trunk/app/models/ ,
compare the Topic and User models to the Monitorship model to see the
range of possibilities.
--f
On 11/9/06, mixplate
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> hi,
> yesterday i ran into an interesting problem which is im sure a silly
> mistake.
>
> do models contain any logic?
>
> for example in my class sale i have this function
>
> define get_category(category)
> if category == 0
> Sale.find_by_sql("Select * from Sales WHERE sale_id = ?",
> category)
> end
> if category != 0
> Sale.find_by_sql("Select * from Sales")
> end
> end
>
>
> however this was not working when displaying data in my view. i tried
> all variations of statements but no luck. When i put the if logic into
> my controller and just created the same if statement in there, i had no
> problem getting the data.
>
> so i was thinking that if there is logic in a model class, than that
> would take away from the controllers powers. is this true?
>
> Thanks,
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---