KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-25 15:04 UTC
Trying to take :locals out of my partial call in Rails 2.1
Mr. Cheung, I was reading your http://www.spacevatican.org/ and in your May 3rd blog you discuss a topic of which I show (below); When I try to take the :locals out of my partial call, the form blows up with this message; You have a nil object when you didn''t expect it! The error occurred while evaluating nil.label Extracted source (around line #2): 1: <p> 2: <%= form.label :account_id %><br /> 3: <%= form.text_field :account_id, :class => ''text_field'', :size => 2 %> 4: </p> I''ve read elsewhere of this new change in Rails 2.1.0 but cannot get my application to behave in this new way. I am certain I am using 2.1. ARTICLE begins here :locals and string keys May 3rd, 2008 If you ever do this render :some_partial, :locals => {''foo'' => ''bar''} don''t. String keys in :locals have been deprecated for a while and are no longer supported in edge (and thus in the not too distant 2.1), so go ahead and change them now and you''ll save yourself some grief when you migrate to 2.1. When things break it''s always nice when they break in an obvious way, so in this case foo not being defined at all in the partial makes it immediately obvious that something has change from :locals. You check the api docs, maybe google around a bit and see that string keys aren''t accepted any more. If you do use a string key like this the foo will still be defined it will just be nil. You probably won''t suspect an api change and spend some time hunting up and down as to why the variable you''re using in :locals is nil (at least that''s what I did - hopefully you won''t have to do the same now!). ARTICLE ends here Thank you, Kathleen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-25 15:08 UTC
Re: Trying to take :locals out of my partial call in Rails 2.1
On 25 Jun 2008, at 16:04, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Mr. Cheung, > I was reading your http://www.spacevatican.org/ and in your May 3rd > blog you discuss a topic of which I show (below); > When I try to take the :locals out of my partial call, the form blows > up with this message; > You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.label > Extracted source (around line #2): > 1: <p> > 2: <%= form.label :account_id %><br /> > 3: <%= form.text_field :account_id, :class => ''text_field'', :size > => 2 %> > 4: </p> > I''ve read elsewhere of this new change in Rails 2.1.0 but cannot get > my application to behave in this new way. I am certain I am using 2.1. >I probably wasn''t quite clear enough. I wasn''t saying don''t use :locals, I was saying don''t use string keys, so :locals => {''foo'' => ''bar''} becomes :locals => {:foo => ''bar''} Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jun-25 15:45 UTC
Re: Trying to take :locals out of my partial call in Rails 2.1
Mr. Cheung, I stumbled upon the fact that if I take the quotes off of ''form'' that it works. <% form_for(@agency) do |form| %> <%= form.error_messages %> <%= render :partial => form %> <p> <%= form.submit "Update" %> </p> <% end %> Then in my _form view it looks something like this; <p> <%= form.label :account_id %><br /> <%= form.text_field :account_id, :class => ''text_field'', :size => 2 %> </p> <p> <%= form.label :description %><br /> <%= form.text_field :description %> </p> Are you saying that I must put the locals back in even though it works? Thank you, Kathleen On Jun 25, 9:08 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 25 Jun 2008, at 16:04, KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > > > > > > > Mr. Cheung, > > I was reading yourhttp://www.spacevatican.org/and in your May 3rd > > blog you discuss a topic of which I show (below); > > When I try to take the :locals out of my partial call, the form blows > > up with this message; > > You have a nil object when you didn''t expect it! > > The error occurred while evaluating nil.label > > Extracted source (around line #2): > > 1: <p> > > 2: <%= form.label :account_id %><br /> > > 3: <%= form.text_field :account_id, :class => ''text_field'', :size > > => 2 %> > > 4: </p> > > I''ve read elsewhere of this new change in Rails 2.1.0 but cannot get > > my application to behave in this new way. I am certain I am using 2.1. > > I probably wasn''t quite clear enough. I wasn''t saying don''t > use :locals, I was saying don''t use string keys, so > > :locals => {''foo'' => ''bar''} > > becomes > > :locals => {:foo => ''bar''} > > Fred- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-25 15:56 UTC
Re: Trying to take :locals out of my partial call in Rails 2.1
On 25 Jun 2008, at 16:45, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Mr. Cheung, > I stumbled upon the fact that if I take the quotes off of ''form'' that > it works. > <% form_for(@agency) do |form| %> > <%= form.error_messages %> > > > <%= render :partial => form %> > > <p> > <%= form.submit "Update" %> > </p> > <% end %> > > Then in my _form view it looks something like this; > > <p> > <%= form.label :account_id %><br /> > <%= form.text_field :account_id, :class => ''text_field'', :size => > 2 %> > </p> > > <p> > <%= form.label :description %><br /> > <%= form.text_field :description %> > </p> > > Are you saying that I must put the locals back in even though it > works?No you don''t need to (that''s another rails 2.1 change, you can pass a form builder to :partial) Fred> > Thank you, > Kathleen > > On Jun 25, 9:08 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 25 Jun 2008, at 16:04, KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> >> >> >> >> >> >> >>> Mr. Cheung, >>> I was reading yourhttp://www.spacevatican.org/and in your May 3rd >>> blog you discuss a topic of which I show (below); >>> When I try to take the :locals out of my partial call, the form >>> blows >>> up with this message; >>> You have a nil object when you didn''t expect it! >>> The error occurred while evaluating nil.label >>> Extracted source (around line #2): >>> 1: <p> >>> 2: <%= form.label :account_id %><br /> >>> 3: <%= form.text_field :account_id, :class => >>> ''text_field'', :size >>> => 2 %> >>> 4: </p> >>> I''ve read elsewhere of this new change in Rails 2.1.0 but cannot get >>> my application to behave in this new way. I am certain I am using >>> 2.1. >> >> I probably wasn''t quite clear enough. I wasn''t saying don''t >> use :locals, I was saying don''t use string keys, so >> >> :locals => {''foo'' => ''bar''} >> >> becomes >> >> :locals => {:foo => ''bar''} >> >> Fred- Hide quoted text - >> >> - Show quoted text - > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---