Erwin
2011-Mar-13 11:42 UTC
undefined method `model_name in partial .. passing an Array as a collection
In the controller , I am passing an Array as a collection
@objects = ["item1", "item2", "item3",
"item4"]
in the view I wrote
%table#objects
= render :partial => ''object'', :collection =>
@objects
and in my partial _object.html
= content_tag_for(:tr, @object) do
%td= @object
%td= link_to........
but I got an error : undefined method `model_name'' for NilClass:Class
for the #object in the content_tag
@object is not not a class..... (yet) I just to want to test on an
Array of string .... anyway of doing such thing ?
thanks for your feedback
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Mar-13 12:34 UTC
Re: undefined method `model_name in partial .. passing an Array as a collection
On Mar 13, 11:42 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> In the controller , I am passing an Array as a collection > @objects = ["item1", "item2", "item3", "item4"] > > in the view I wrote > %table#objects > = render :partial => ''object'', :collection => @objects > > and in my partial _object.html > = content_tag_for(:tr, @object) do > %td= @object > %td= link_to........ > > but I got an error : undefined method `model_name'' for NilClass:Class > for the #object in the content_tag > > @object is not not a class..... (yet) I just to want to test on an > Array of string .... anyway of doing such thing ?@object isn''t set - you should be using object (since that''s what render will be filling with the items from @objects Fred> > thanks for your feedback-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Erwin
2011-Mar-13 13:10 UTC
Re: undefined method `model_name in partial .. passing an Array as a collection
Thanks fred.. I tried with object but same error.. it seems model_name_from_record_or_class is needed when using collection I may have to change the partial rendering ... ? -- trace activemodel (3.0.4) lib/active_model/naming.rb:94:in `model_name_from_record_or_class'' activemodel (3.0.4) lib/active_model/naming.rb:81:in `singular'' actionpack (3.0.4) lib/action_controller/record_identifier.rb:49:in `dom_class'' actionpack (3.0.4) lib/action_view/helpers/record_tag_helper.rb:58:in `content_tag_for'' app/views/admin/remote_lockers/_object.html.haml:1:in `_app_views_admin_remote_lockers__object_html_haml__3334574884651529235_2179828200_2175116202532159367'' actionpack (3.0.4) lib/action_view/template.rb:135:in `block in render'' activesupport (3.0.4) lib/active_support/notifications.rb:54:in `instrument'' actionpack (3.0.4) lib/action_view/template.rb:127:in `render'' actionpack (3.0.4) lib/action_view/render/partials.rb:300:in `block in collection_with_template'' actionpack (3.0.4) lib/action_view/render/partials.rb:297:in `each'' actionpack (3.0.4) lib/action_view/render/partials.rb:297:in `collection_with_template'' actionpack (3.0.4) lib/action_view/render/partials.rb:280:in `render_collection'' On 13 mar, 13:34, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 13, 11:42 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > > > > > > > > In the controller , I am passing an Array as a collection > > @objects = ["item1", "item2", "item3", "item4"] > > > in the view I wrote > > %table#objects > > = render :partial => ''object'', :collection => @objects > > > and in my partial _object.html > > = content_tag_for(:tr, @object) do > > %td= @object > > %td= link_to........ > > > but I got an error : undefined method `model_name'' for NilClass:Class > > for the #object in the content_tag > > > @object is not not a class..... (yet) I just to want to test on an > > Array of string .... anyway of doing such thing ? > > @object isn''t set - you should be using object (since that''s what > render will be filling with the items from @objects > > Fred > > > > > > > > > > > thanks for your feedback-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Erwin
2011-Mar-13 13:28 UTC
Re: undefined method `model_name in partial .. passing an Array as a collection
to avoid being confused with ''object'' litteral .. I modified the test code as following : #lockers %table#items = render :partial => ''item'', :collection => [''foo'', ''bar'', ''baz''] and the _item partial = content_tag_for(:tr, item) do %td= item this time , the error is : undefined method `model_name'' for String:Class I believe there is something wrong with the content_tag_for... On 13 mar, 13:34, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 13, 11:42 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > > > > > > > > In the controller , I am passing an Array as a collection > > @objects = ["item1", "item2", "item3", "item4"] > > > in the view I wrote > > %table#objects > > = render :partial => ''object'', :collection => @objects > > > and in my partial _object.html > > = content_tag_for(:tr, @object) do > > %td= @object > > %td= link_to........ > > > but I got an error : undefined method `model_name'' for NilClass:Class > > for the #object in the content_tag > > > @object is not not a class..... (yet) I just to want to test on an > > Array of string .... anyway of doing such thing ? > > @object isn''t set - you should be using object (since that''s what > render will be filling with the items from @objects > > Fred > > > > > > > > > > > thanks for your feedback-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Frederick Cheung
2011-Mar-13 14:12 UTC
Re: undefined method `model_name in partial .. passing an Array as a collection
On Mar 13, 1:28 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> to avoid being confused with ''object'' litteral .. I modified the test > code as following : > > #lockers > %table#items > = render :partial => ''item'', :collection => [''foo'', ''bar'', ''baz''] > > and the _item partial > > = content_tag_for(:tr, item) do > %td= item > > this time , the error is : undefined method `model_name'' for > String:Class > > I believe there is something wrong with the content_tag_for... >Oops, hadn''t spotted that you were using content_tag for as opposed to content_tag. The entire point of content_tag_for is that you give it an activemodel like object and it will set the dom id & css class appropriately. If you don''t have such objects (eg you have strings instead), then don''t use content_tag_for. content_tag might be what you''re looking for. Fred> On 13 mar, 13:34, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Mar 13, 11:42 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > In the controller , I am passing an Array as a collection > > > @objects = ["item1", "item2", "item3", "item4"] > > > > in the view I wrote > > > %table#objects > > > = render :partial => ''object'', :collection => @objects > > > > and in my partial _object.html > > > = content_tag_for(:tr, @object) do > > > %td= @object > > > %td= link_to........ > > > > but I got an error : undefined method `model_name'' for NilClass:Class > > > for the #object in the content_tag > > > > @object is not not a class..... (yet) I just to want to test on an > > > Array of string .... anyway of doing such thing ? > > > @object isn''t set - you should be using object (since that''s what > > render will be filling with the items from @objects > > > Fred > > > > thanks for your feedback-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Erwin
2011-Mar-13 14:15 UTC
Re: undefined method `model_name in partial .. passing an Array as a collection
thanks you confirm it .. I noticed it as I change my test code using the array as the collection .... it''s fine now ... using content_tag obvious thing doesn''t appears at first glance !! On 13 mar, 15:12, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mar 13, 1:28 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > > > > > > > > to avoid being confused with ''object'' litteral .. I modified the test > > code as following : > > > #lockers > > %table#items > > = render :partial => ''item'', :collection => [''foo'', ''bar'', ''baz''] > > > and the _item partial > > > = content_tag_for(:tr, item) do > > %td= item > > > this time , the error is : undefined method `model_name'' for > > String:Class > > > I believe there is something wrong with the content_tag_for... > > Oops, hadn''t spotted that you were using content_tag for as opposed to > content_tag. The entire point of content_tag_for is that you give it > an activemodel like object and it will set the dom id & css class > appropriately. > If you don''t have such objects (eg you have strings instead), then > don''t use content_tag_for. content_tag might be what you''re looking > for. > > Fred > > > > > > > > > On 13 mar, 13:34, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Mar 13, 11:42 am, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote: > > > > > In the controller , I am passing an Array as a collection > > > > @objects = ["item1", "item2", "item3", "item4"] > > > > > in the view I wrote > > > > %table#objects > > > > = render :partial => ''object'', :collection => @objects > > > > > and in my partial _object.html > > > > = content_tag_for(:tr, @object) do > > > > %td= @object > > > > %td= link_to........ > > > > > but I got an error : undefined method `model_name'' for NilClass:Class > > > > for the #object in the content_tag > > > > > @object is not not a class..... (yet) I just to want to test on an > > > > Array of string .... anyway of doing such thing ? > > > > @object isn''t set - you should be using object (since that''s what > > > render will be filling with the items from @objects > > > > Fred > > > > > thanks for your feedback-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org 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.
Curtis j Schofield
2011-Mar-13 16:46 UTC
Re: undefined method `model_name in partial .. passing an Array as a collection
On Sun, Mar 13, 2011 at 4:42 AM, Erwin <yves_dufour-ee4meeAH724@public.gmane.org> wrote:> In the controller , I am passing an Array as a collection > @objects = ["item1", "item2", "item3", "item4"] > > > in the view I wrote > %table#objects > = render :partial => ''object'', :collection => @objects > > and in my partial _object.html > = content_tag_for(:tr, @object) do > %td= @object > %td= link_to........ > >you are using the partial in the wrong way. when you use :collection => @objects it will pass each element of the collection into the partial and create ''object'' which is created based on the name of the partial ''_name''. the same thing happens with :partial ''thing'', :object => Thing.new _thing.haml = thing # this is the :object, based on the name also call your partial .haml if it is haml. -- make haste slowly \ festina lente \ - mobile +1_415_632_6001 curtis.schofield-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <curtis-DDU1nqEjlGkHaT8GDLgCUg@public.gmane.org> http://robotarmyma.de -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.