Re: [Rails] Fragment caching and not accessing model from view
On 9 March 2011 09:19, Jatin kumar <jatinkumar.nitk@gmail.com> wrote:
> On Tue, Mar 8, 2011 at 4:06 PM, Colin Law <clanlaw@googlemail.com> wrote:
>> <%= f.collection_select :variety_id, Variety.all, :id, :name %>
>>
> Yes, you are right. One should not access the model from the view.
>
> Create a method in the model, say
>
> def self.your_method_name
> your_query
> end
>
> and then you can access the model in your view, using the method you just
> defined in the model.
I don't see how:
<%= f.collection_select :variety_id, Variety.all, :id, :name %>
is different from :
<%= f.collection_select :variety_id, Variety.your_method_name, :id, :name %>
?:-/
If you say in one breath "don't access models from the view" and then
in the next create a model class method... how's that different from
using the ".all" class method?
(btw I agree that one shouldn't access the model from the view - I'm
just querying that your suggestion may not remove this MVC-breaking
practice in this instance)
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home