On Jul 27, 2009, at 12:26 PM, Ashley wrote:
> Hello guys!
>
> Question:
>
> Views should be "dumb" and models should deal with db queries...
>
> but what if you have a situation like so
>
> class User < ActiveRecord::Base
>
>  def has_relationship_with?( other_user )
>    !relationships.find_by_other_user_id( other_user.id ).nil?
>  end
> end
>
> and then in your view:
>
> <%= "Display this message" if @user.has_relationship_with?
> (@other_user) %>
>
> Is it cool to call model methods which, in turn, query the db within
> the view or is there a better way of implementing this?
>
> Thanks
>
> ASH

This should be fine, but you might want to think about whether you  
need to "eager load" the relationships assosciation for performance.

The benefit is that your model contains the code and you can  
potentially refactor without touching your view.

-Rob

Rob Biedenharn          http://agileconsultingllc.com
[email protected]



--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to