Hey folks,
I''m having major issues trying to complete a simple task.
Goal:
Create a drop-down list and populate it with states. When the user
fills out the form and saves, the state selected should be saved with
the record.
Problem:
When trying to save the record I get the following error:
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.inject
And it points to this line in my .rthml:
<%= select_tag ''state'', options_for_select(@states) %>
And here is my controller code in the ''new'' method:
def new
@client = Client.new
@states = %w{-select- AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN
IA KS KY
LA ME MH MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND
OH OK
OR PA RI SC SD TN TX UT VT VI VA WA WV WI WY}
end
The list populates fine with states, but bombs when I try to save.
Please help.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hey folks,
I''m having major issues trying to complete a simple task.
Goal:
Create a drop-down list and populate it with states. When the user
fills out the form and saves, the state selected should be saved with
the record.
Problem:
When trying to save the record I get the following error:
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.inject
And it points to this line in my .rthml:
<%= select_tag ''state'', options_for_select(@states) %>
And here is my controller code in the ''new'' method:
def new
@client = Client.new
@states = %w{-select- AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN
IA KS KY
LA ME MH MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND
OH OK
OR PA RI SC SD TN TX UT VT VI VA WA WV WI WY}
end
The list populates fine with states, but bombs when I try to save.
Please help.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
longint wrote:> Hey folks, > > I''m having major issues trying to complete a simple task. > > Goal: > Create a drop-down list and populate it with states. When the user > fills out the form and saves, the state selected should be saved with > the record. >snip... and the save code looks like?
I had created a static scaffold, so this is what Rails'' produced:
def create
@client = Client.new(params[:client])
if @client.save
flash[:notice] = ''Client was successfully created.''
redirect_to :action => ''list''
else
render :action => ''new''
end
end
On May 20, 4:35 pm, Sean T Allen
<s...-j6/ZtAoqnBr6dDqEjws1Cg@public.gmane.org>
wrote:> longint wrote:
> > Hey folks,
>
> > I''m having major issues trying to complete a simple task.
>
> > Goal:
> > Create a drop-down list and populate it with states. When the user
> > fills out the form and saves, the state selected should be saved with
> > the record.
>
> snip...
>
> and the save code looks like?
>
> smime.p7s
> 5KDownload
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
in your model, is state just a string? longint wrote:> I had created a static scaffold, so this is what Rails'' produced: > > def create > @client = Client.new(params[:client]) > if @client.save > flash[:notice] = ''Client was successfully created.'' > redirect_to :action => ''list'' > else > render :action => ''new'' > end > end > > On May 20, 4:35 pm, Sean T Allen <s...-j6/ZtAoqnBr6dDqEjws1Cg@public.gmane.org> wrote: > >> longint wrote: >> >>> Hey folks, >>> >>> I''m having major issues trying to complete a simple task. >>> >>> Goal: >>> Create a drop-down list and populate it with states. When the user >>> fills out the form and saves, the state selected should be saved with >>> the record. >>> >> snip... >> >> and the save code looks like? >> >> smime.p7s >> 5KDownload >> > > > --~--~---------~--~----~------------~-------~--~----~ > 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 > -~----------~----~----~----~------~----~------~--~--- > >
Yeah, state is a string in my model. On May 20, 5:29 pm, Sean T Allen <s...-j6/ZtAoqnBr6dDqEjws1Cg@public.gmane.org> wrote:> in your model, is state just a string? > > longint wrote: > > I had created a static scaffold, so this is what Rails'' produced: > > > def create > > @client = Client.new(params[:client]) > > if @client.save > > flash[:notice] = ''Client was successfully created.'' > > redirect_to :action => ''list'' > > else > > render :action => ''new'' > > end > > end > > > On May 20, 4:35 pm, Sean T Allen <s...-j6/ZtAoqnBr6dDqEjws1Cg@public.gmane.org> wrote: > > >> longint wrote: > > >>> Hey folks, > > >>> I''m having major issues trying to complete a simple task. > > >>> Goal: > >>> Create a drop-down list and populate it with states. When the user > >>> fills out the form and saves, the state selected should be saved with > >>> the record. > > >> snip... > > >> and the save code looks like? > > >> smime.p7s > >> 5KDownload > > > > > > > smime.p7s > 5KDownload--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
your html from the select is just state period. not state that is part
of client.
this:
<%= select_tag ''state'', options_for_select(@states) %>
just creates
<select id="state" name="state">
... options ...
</select>
for that scaffold code to work you want
<select id="client_state" name="client[state]">
... options ...
</select>
off the top of my head, you could use select...
<%= select ''client'', ''state'',
@states.collect{ |s| [ s, s ] } %>
but that shouldnt be were that nil inject error is coming from.
are you sure the error is in your create method and not in either
the redirect on the on the re-rendering?
longint wrote:> Yeah, state is a string in my model.
>
> On May 20, 5:29 pm, Sean T Allen
<s...-j6/ZtAoqnBr6dDqEjws1Cg@public.gmane.org> wrote:
>
>> in your model, is state just a string?
>>
>> longint wrote:
>>
>>> I had created a static scaffold, so this is what Rails''
produced:
>>>
>>> def create
>>> @client = Client.new(params[:client])
>>> if @client.save
>>> flash[:notice] = ''Client was successfully
created.''
>>> redirect_to :action => ''list''
>>> else
>>> render :action => ''new''
>>> end
>>> end
>>>
>>> On May 20, 4:35 pm, Sean T Allen
<s...-j6/ZtAoqnBr6dDqEjws1Cg@public.gmane.org> wrote:
>>>
>>>> longint wrote:
>>>>
>>>>> Hey folks,
>>>>>
>>>>> I''m having major issues trying to complete a
simple task.
>>>>>
>>>>> Goal:
>>>>> Create a drop-down list and populate it with states. When
the user
>>>>> fills out the form and saves, the state selected should be
saved with
>>>>> the record.
>>>>>
>>>> snip...
>>>>
>>>> and the save code looks like?
>>>>
>>>> smime.p7s
>>>> 5KDownload
>>>>
>> smime.p7s
>> 5KDownload
>>
>
>
> --~--~---------~--~----~------------~-------~--~----~
> 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
> -~----------~----~----~----~------~----~------~--~---
>
>