librelist archives

« back to archive

Scratching my head on this one

Scratching my head on this one

From:
Steve
Date:
2012-07-19 @ 21:35
Here's a question I'm completely stumped on. I've been looking at Stack 
Overflow and other places for a while now and can't seem to find the 
answer.

I'm trying to create a drop down selection to pull the publisher_id from 
the publisher table. This is the code in the new.html.erb file: 
<%= select_tag "issue", options_from_collection_for_select(@publisher, 
"id", "name") %>

The controller file looks like this:

class IssuesController < ApplicationController
  def show
  	@issue = Issue.find(params[:id])
  end
  
  def new
  	@issue = Issue.new
  end
  
  def create
  	@issue = Issue.new(params[:issue])
  		if @issue.save
  		
  		else
  			render 'new'
  	end	
  end
 end 

Routes look like this:

ComicbookApp::Application.routes.draw do

 resources :issues
 

  root to: "static_pages#home"

  match '/issue', to: 'issues#new'
  match '/publisher', to: 'publishers#new'
  resources :publishers, only: [:new, :create]

If you need more let me know.

Here is the error: 

NoMethodError in Issues#new

Showing 
/Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb 
where line #16 raised:

undefined method `map' for nil:NilClass

Extracted source (around line #16):

13:  			<%= f.label  :villain%>
14:  			<%= f.text_field :villain %><br /><br />
15:  			
16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
17:  			<%=  %><br />
18:  			
19:  			<%= f.submit "Create the Issue", class: "btn btn-large btn-primary" %>
Thanks, 

Steve

Re: [getarailsjob] Scratching my head on this one

From:
Allen Maxwell
Date:
2012-07-19 @ 21:59
First thing I see is the error message which is saying you (or the system)
is trying to do a map call on a nil object.

from the code you've posted you're doing an explicit map so it's probably 
happening inside the options_from_collection_for_select call.

I don't see anywhere that you've defined the @publisher variable which is 
what I'm guessing is the problem.  if you're form is the edit form, you 
probably want to put a call to populate that variable so it can populate 
the select.  something like:

@publisher = Publisher.all


also, there should be a stack trace after the error info you posted.  that
might be helpful next time too… (if it's there).

Hope this helps.

Max


On Jul 19, 2012, at 3:35 PM, Steve wrote:

> Here's a question I'm completely stumped on. I've been looking at Stack 
Overflow and other places for a while now and can't seem to find the 
answer.
> 
> I'm trying to create a drop down selection to pull the publisher_id from
the publisher table. This is the code in the new.html.erb file: 
> <%= select_tag "issue", options_from_collection_for_select(@publisher, 
"id", "name") %>
> 
> The controller file looks like this:
> 
> class IssuesController < ApplicationController
>   def show
>   	@issue = Issue.find(params[:id])
>   end
>   
>   def new
>   	@issue = Issue.new
>   end
>   
>   def create
>   	@issue = Issue.new(params[:issue])
>   		if @issue.save
>   		
>   		else
>   			render 'new'
>   	end	
>   end
>  end 
> 
> Routes look like this:
> 
> ComicbookApp::Application.routes.draw do
> 
>  resources :issues
>  
> 
>   root to: "static_pages#home"
> 
>   match '/issue', to: 'issues#new'
>   match '/publisher', to: 'publishers#new'
>   resources :publishers, only: [:new, :create]
> 
> If you need more let me know.
> 
> Here is the error: 
> 
> NoMethodError in Issues#new
> 
> Showing 
/Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb 
where line #16 raised:
> 
> undefined method `map' for nil:NilClass
> 
> Extracted source (around line #16):
> 
> 13:  			<%= f.label  :villain%>
> 14:  			<%= f.text_field :villain %><br /><br />
> 15:  			
> 16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
> 17:  			<%=  %><br />
> 18:  			
> 19:  			<%= f.submit "Create the Issue", class: "btn btn-large btn-primary" %>
> Thanks, 
> 
> Steve

Re: [getarailsjob] Scratching my head on this one

From:
Steve
Date:
2012-07-19 @ 22:07
I'll be danged. Publisher.all worked. Cool.

Thanks. I really need to learn how to define my variables.

Steve


On Jul 19, 2012, at 3:59 PM, Allen Maxwell wrote:

> First thing I see is the error message which is saying you (or the 
system) is trying to do a map call on a nil object.
> 
> from the code you've posted you're doing an explicit map so it's 
probably happening inside the options_from_collection_for_select call.
> 
> I don't see anywhere that you've defined the @publisher variable which 
is what I'm guessing is the problem.  if you're form is the edit form, you
probably want to put a call to populate that variable so it can populate 
the select.  something like:
> 
> @publisher = Publisher.all
> 
> 
> also, there should be a stack trace after the error info you posted.  
that might be helpful next time too… (if it's there).
> 
> Hope this helps.
> 
> Max
> 
> 
> On Jul 19, 2012, at 3:35 PM, Steve wrote:
> 
>> Here's a question I'm completely stumped on. I've been looking at Stack
Overflow and other places for a while now and can't seem to find the 
answer.
>> 
>> I'm trying to create a drop down selection to pull the publisher_id 
from the publisher table. This is the code in the new.html.erb file: 
>> <%= select_tag "issue", options_from_collection_for_select(@publisher, 
"id", "name") %>
>> 
>> The controller file looks like this:
>> 
>> class IssuesController < ApplicationController
>>   def show
>>   	@issue = Issue.find(params[:id])
>>   end
>>   
>>   def new
>>   	@issue = Issue.new
>>   end
>>   
>>   def create
>>   	@issue = Issue.new(params[:issue])
>>   		if @issue.save
>>   		
>>   		else
>>   			render 'new'
>>   	end	
>>   end
>>  end 
>> 
>> Routes look like this:
>> 
>> ComicbookApp::Application.routes.draw do
>> 
>>  resources :issues
>>  
>> 
>>   root to: "static_pages#home"
>> 
>>   match '/issue', to: 'issues#new'
>>   match '/publisher', to: 'publishers#new'
>>   resources :publishers, only: [:new, :create]
>> 
>> If you need more let me know.
>> 
>> Here is the error: 
>> 
>> NoMethodError in Issues#new
>> 
>> Showing 
/Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb 
where line #16 raised:
>> 
>> undefined method `map' for nil:NilClass
>> 
>> Extracted source (around line #16):
>> 
>> 13:  			<%= f.label  :villain%>
>> 14:  			<%= f.text_field :villain %><br /><br />
>> 15:  			
>> 16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
>> 17:  			<%=  %><br />
>> 18:  			
>> 19:  			<%= f.submit "Create the Issue", class: "btn btn-large btn-primary" %>
>> Thanks, 
>> 
>> Steve
> 

Re: [getarailsjob] Scratching my head on this one

From:
David Richards
Date:
2012-07-19 @ 22:09
Ah, now that I think about this, Publisher.all will let you choose any
publisher and issue.publishers will only allow you to change which
publisher, which I think was the edge case, right?  I think you want
@publishers = Publisher.all in your controller.

On Thu, Jul 19, 2012 at 4:07 PM, Steve <steve@mach4ws.com> wrote:

> I'll be danged. Publisher.all worked. Cool.
>
> Thanks. I really need to learn how to define my variables.
>
> Steve
>
>
> On Jul 19, 2012, at 3:59 PM, Allen Maxwell wrote:
>
> First thing I see is the error message which is saying you (or the system)
> is trying to do a map call on a nil object.
>
> from the code you've posted you're doing an explicit map so it's probably
> happening inside the options_from_collection_for_select call.
>
> I don't see anywhere that you've defined the @publisher variable which is
> what I'm guessing is the problem.  if you're form is the edit form, you
> probably want to put a call to populate that variable so it can populate
> the select.  something like:
>
> @publisher = Publisher.all
>
>
> also, there should be a stack trace after the error info you posted.  that
> might be helpful next time too… (if it's there).
>
> Hope this helps.
>
> Max
>
>
> On Jul 19, 2012, at 3:35 PM, Steve wrote:
>
> Here's a question I'm completely stumped on. I've been looking at Stack
> Overflow and other places for a while now and can't seem to find the answer.
>
> I'm trying to create a drop down selection to pull the publisher_id from
> the publisher table. This is the code in the new.html.erb file:
> <%= select_tag "issue", options_from_collection_for_select(@publisher,
> "id", "name") %>
>
> The controller file looks like this:
>
> class IssuesController < ApplicationController
>   def show
>   @issue = Issue.find(params[:id])
>   end
>
>   def new
>   @issue = Issue.new
> **  end**
>
>   def create
>   @issue = Issue.new(params[:issue])
>   if @issue.save
>
>   else
>   render 'new'
>   end
>   end
>  end
>
> Routes look like this:
>
> ComicbookApp::Application.routes.draw do
>
>  resources :issues
>
>
>   root to: "static_pages#home"
>
>   match '/issue', to: 'issues#new'
>   match '/publisher', to: 'publishers#new'
>   resources :publishers, only: [:new, :create]
>
> If you need more let me know.
>
> Here is the error:
>
> NoMethodError in Issues#new
>
> Showing *
> /Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb* where
> line *#16* raised:
>
> undefined method `map' for nil:NilClass
>
>
> Extracted source (around line *#16*):
>
> 13:  			<%= f.label  :villain%>
> 14:  			<%= f.text_field :villain %><br /><br />
> 15:  			
> 16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
> 17:  			<%=  %><br />
> 18:  			
> 19:  			<%= f.submit "Create the Issue", class: "btn btn-large btn-primary" %>
>
> Thanks,
>
> Steve
>
>
>
>

Re: [getarailsjob] Scratching my head on this one

From:
Steve
Date:
2012-07-19 @ 22:15
I put the definition like so: <%= select_tag "issue", 
options_from_collection_for_select(@publisher = Publisher.all, "id", 
"name") %>

It worked fine. I wasn't sure where to put it in the controller. I guess I
could define a method for select or something, but is there a problem with
putting it inline?

Steve


On Jul 19, 2012, at 4:09 PM, David Richards wrote:

> Ah, now that I think about this, Publisher.all will let you choose any 
publisher and issue.publishers will only allow you to change which 
publisher, which I think was the edge case, right?  I think you want 
@publishers = Publisher.all in your controller.
> 
> On Thu, Jul 19, 2012 at 4:07 PM, Steve <steve@mach4ws.com> wrote:
> I'll be danged. Publisher.all worked. Cool.
> 
> Thanks. I really need to learn how to define my variables.
> 
> Steve
> 
> 
> On Jul 19, 2012, at 3:59 PM, Allen Maxwell wrote:
> 
>> First thing I see is the error message which is saying you (or the 
system) is trying to do a map call on a nil object.
>> 
>> from the code you've posted you're doing an explicit map so it's 
probably happening inside the options_from_collection_for_select call.
>> 
>> I don't see anywhere that you've defined the @publisher variable which 
is what I'm guessing is the problem.  if you're form is the edit form, you
probably want to put a call to populate that variable so it can populate 
the select.  something like:
>> 
>> @publisher = Publisher.all
>> 
>> 
>> also, there should be a stack trace after the error info you posted.  
that might be helpful next time too… (if it's there).
>> 
>> Hope this helps.
>> 
>> Max
>> 
>> 
>> On Jul 19, 2012, at 3:35 PM, Steve wrote:
>> 
>>> Here's a question I'm completely stumped on. I've been looking at 
Stack Overflow and other places for a while now and can't seem to find the
answer.
>>> 
>>> I'm trying to create a drop down selection to pull the publisher_id 
from the publisher table. This is the code in the new.html.erb file: 
>>> <%= select_tag "issue", options_from_collection_for_select(@publisher,
"id", "name") %>
>>> 
>>> The controller file looks like this:
>>> 
>>> class IssuesController < ApplicationController
>>>   def show
>>>   	@issue = Issue.find(params[:id])
>>>   end
>>>   
>>>   def new
>>>   	@issue = Issue.new
>>>   end
>>>   
>>>   def create
>>>   	@issue = Issue.new(params[:issue])
>>>   		if @issue.save
>>>   		
>>>   		else
>>>   			render 'new'
>>>   	end	
>>>   end
>>>  end 
>>> 
>>> Routes look like this:
>>> 
>>> ComicbookApp::Application.routes.draw do
>>> 
>>>  resources :issues
>>>  
>>> 
>>>   root to: "static_pages#home"
>>> 
>>>   match '/issue', to: 'issues#new'
>>>   match '/publisher', to: 'publishers#new'
>>>   resources :publishers, only: [:new, :create]
>>> 
>>> If you need more let me know.
>>> 
>>> Here is the error: 
>>> 
>>> NoMethodError in Issues#new
>>> 
>>> Showing 
/Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb 
where line #16 raised:
>>> 
>>> undefined method `map' for nil:NilClass
>>> 
>>> Extracted source (around line #16):
>>> 
>>> 13:  			<%= f.label  :villain%>
>>> 14:  			<%= f.text_field :villain %><br /><br />
>>> 15:  			
>>> 16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
>>> 17:  			<%=  %><br />
>>> 18:  			
>>> 19:  			<%= f.submit "Create the Issue", class: "btn btn-large btn-primary" %>
>>> Thanks, 
>>> 
>>> Steve
>> 
> 
> 

Re: [getarailsjob] Scratching my head on this one

From:
Allen Maxwell
Date:
2012-07-19 @ 22:48
I would not put it there… you want to try and keep your logic in either 
the controller or model (depends on what it is).

depending on which "action" this form is generated from = that is where 
you need to @publisher = Publisher.all.

if this is an edit action (you're editing an issue) the put it in the edit
action of the controller:

def edit 
	@publisher = Publisher.all
end

you'll probably want it in the new action too.




On Jul 19, 2012, at 4:15 PM, Steve wrote:

> I put the definition like so: <%= select_tag "issue", 
options_from_collection_for_select(@publisher = Publisher.all, "id", 
"name") %>
> 
> It worked fine. I wasn't sure where to put it in the controller. I guess
I could define a method for select or something, but is there a problem 
with putting it inline?
> 
> Steve
> 
> 
> On Jul 19, 2012, at 4:09 PM, David Richards wrote:
> 
>> Ah, now that I think about this, Publisher.all will let you choose any 
publisher and issue.publishers will only allow you to change which 
publisher, which I think was the edge case, right?  I think you want 
@publishers = Publisher.all in your controller.
>> 
>> On Thu, Jul 19, 2012 at 4:07 PM, Steve <steve@mach4ws.com> wrote:
>> I'll be danged. Publisher.all worked. Cool.
>> 
>> Thanks. I really need to learn how to define my variables.
>> 
>> Steve
>> 
>> 
>> On Jul 19, 2012, at 3:59 PM, Allen Maxwell wrote:
>> 
>>> First thing I see is the error message which is saying you (or the 
system) is trying to do a map call on a nil object.
>>> 
>>> from the code you've posted you're doing an explicit map so it's 
probably happening inside the options_from_collection_for_select call.
>>> 
>>> I don't see anywhere that you've defined the @publisher variable which
is what I'm guessing is the problem.  if you're form is the edit form, you
probably want to put a call to populate that variable so it can populate 
the select.  something like:
>>> 
>>> @publisher = Publisher.all
>>> 
>>> 
>>> also, there should be a stack trace after the error info you posted.  
that might be helpful next time too… (if it's there).
>>> 
>>> Hope this helps.
>>> 
>>> Max
>>> 
>>> 
>>> On Jul 19, 2012, at 3:35 PM, Steve wrote:
>>> 
>>>> Here's a question I'm completely stumped on. I've been looking at 
Stack Overflow and other places for a while now and can't seem to find the
answer.
>>>> 
>>>> I'm trying to create a drop down selection to pull the publisher_id 
from the publisher table. This is the code in the new.html.erb file: 
>>>> <%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
>>>> 
>>>> The controller file looks like this:
>>>> 
>>>> class IssuesController < ApplicationController
>>>>   def show
>>>>   	@issue = Issue.find(params[:id])
>>>>   end
>>>>   
>>>>   def new
>>>>   	@issue = Issue.new
>>>>   end
>>>>   
>>>>   def create
>>>>   	@issue = Issue.new(params[:issue])
>>>>   		if @issue.save
>>>>   		
>>>>   		else
>>>>   			render 'new'
>>>>   	end	
>>>>   end
>>>>  end 
>>>> 
>>>> Routes look like this:
>>>> 
>>>> ComicbookApp::Application.routes.draw do
>>>> 
>>>>  resources :issues
>>>>  
>>>> 
>>>>   root to: "static_pages#home"
>>>> 
>>>>   match '/issue', to: 'issues#new'
>>>>   match '/publisher', to: 'publishers#new'
>>>>   resources :publishers, only: [:new, :create]
>>>> 
>>>> If you need more let me know.
>>>> 
>>>> Here is the error: 
>>>> 
>>>> NoMethodError in Issues#new
>>>> 
>>>> Showing 
/Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb 
where line #16 raised:
>>>> 
>>>> undefined method `map' for nil:NilClass
>>>> 
>>>> Extracted source (around line #16):
>>>> 
>>>> 13:  			<%= f.label  :villain%>
>>>> 14:  			<%= f.text_field :villain %><br /><br />
>>>> 15:  			
>>>> 16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
>>>> 17:  			<%=  %><br />
>>>> 18:  			
>>>> 19:  			<%= f.submit "Create the Issue", class: "btn btn-large 
btn-primary" %>
>>>> Thanks, 
>>>> 
>>>> Steve
>>> 
>> 
>> 
> 

Re: [getarailsjob] Scratching my head on this one

From:
Allen Maxwell
Date:
2012-07-19 @ 22:10
fingers typing crap.. sorry.

On Jul 19, 2012, at 3:59 PM, Allen Maxwell wrote:

> First thing I see is the error message which is saying you (or the 
system) is trying to do a map call on a nil object.
> 
> from the code you've posted you're NOT doing an explicit map so it's 
probably happening inside the options_from_collection_for_select call.
> 
> I don't see anywhere that you've defined the @publisher variable which 
is what I'm guessing is the problem.  if you're form is the edit form, you
probably want to put a call to populate that variable so it can populate 
the select.  something like:
> 
> @publisher = Publisher.all
> 
> 
> also, there should be a stack trace after the error info you posted.  
that might be helpful next time too… (if it's there).
> 
> Hope this helps.
> 
> Max
> 
> 
> On Jul 19, 2012, at 3:35 PM, Steve wrote:
> 
>> Here's a question I'm completely stumped on. I've been looking at Stack
Overflow and other places for a while now and can't seem to find the 
answer.
>> 
>> I'm trying to create a drop down selection to pull the publisher_id 
from the publisher table. This is the code in the new.html.erb file: 
>> <%= select_tag "issue", options_from_collection_for_select(@publisher, 
"id", "name") %>
>> 
>> The controller file looks like this:
>> 
>> class IssuesController < ApplicationController
>>   def show
>>   	@issue = Issue.find(params[:id])
>>   end
>>   
>>   def new
>>   	@issue = Issue.new
>>   end
>>   
>>   def create
>>   	@issue = Issue.new(params[:issue])
>>   		if @issue.save
>>   		
>>   		else
>>   			render 'new'
>>   	end	
>>   end
>>  end 
>> 
>> Routes look like this:
>> 
>> ComicbookApp::Application.routes.draw do
>> 
>>  resources :issues
>>  
>> 
>>   root to: "static_pages#home"
>> 
>>   match '/issue', to: 'issues#new'
>>   match '/publisher', to: 'publishers#new'
>>   resources :publishers, only: [:new, :create]
>> 
>> If you need more let me know.
>> 
>> Here is the error: 
>> 
>> NoMethodError in Issues#new
>> 
>> Showing 
/Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb 
where line #16 raised:
>> 
>> undefined method `map' for nil:NilClass
>> 
>> Extracted source (around line #16):
>> 
>> 13:  			<%= f.label  :villain%>
>> 14:  			<%= f.text_field :villain %><br /><br />
>> 15:  			
>> 16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
>> 17:  			<%=  %><br />
>> 18:  			
>> 19:  			<%= f.submit "Create the Issue", class: "btn btn-large btn-primary" %>
>> Thanks, 
>> 
>> Steve
> 

Re: [getarailsjob] Scratching my head on this one

From:
David Richards
Date:
2012-07-19 @ 22:08
I second what Max says.  options_from_collection_for_select expects an
Array-like structure.  I think you can do issue.publishers, if the
structure is like what we did the other day.  So:

select_tag "issue", options_from_collection_for_select issue.publishers,
"id", "name

or something close to that.



On Thu, Jul 19, 2012 at 3:59 PM, Allen Maxwell <aamax@xmission.com> wrote:

> First thing I see is the error message which is saying you (or the system)
> is trying to do a map call on a nil object.
>
> from the code you've posted you're doing an explicit map so it's probably
> happening inside the options_from_collection_for_select call.
>
> I don't see anywhere that you've defined the @publisher variable which is
> what I'm guessing is the problem.  if you're form is the edit form, you
> probably want to put a call to populate that variable so it can populate
> the select.  something like:
>
> @publisher = Publisher.all
>
>
> also, there should be a stack trace after the error info you posted.  that
> might be helpful next time too… (if it's there).
>
> Hope this helps.
>
> Max
>
>
> On Jul 19, 2012, at 3:35 PM, Steve wrote:
>
> Here's a question I'm completely stumped on. I've been looking at Stack
> Overflow and other places for a while now and can't seem to find the answer.
>
> I'm trying to create a drop down selection to pull the publisher_id from
> the publisher table. This is the code in the new.html.erb file:
> <%= select_tag "issue", options_from_collection_for_select(@publisher,
> "id", "name") %>
>
> The controller file looks like this:
>
> class IssuesController < ApplicationController
>   def show
>   @issue = Issue.find(params[:id])
>   end
>
>   def new
>   @issue = Issue.new
> **  end**
>
>   def create
>   @issue = Issue.new(params[:issue])
>   if @issue.save
>
>   else
>   render 'new'
>   end
>   end
>  end
>
> Routes look like this:
>
> ComicbookApp::Application.routes.draw do
>
>  resources :issues
>
>
>   root to: "static_pages#home"
>
>   match '/issue', to: 'issues#new'
>   match '/publisher', to: 'publishers#new'
>   resources :publishers, only: [:new, :create]
>
> If you need more let me know.
>
> Here is the error:
>
> NoMethodError in Issues#new
>
> Showing *
> /Users/admin/local/rails_apps/comicbook_app/app/views/issues/new.html.erb* where
> line *#16* raised:
>
> undefined method `map' for nil:NilClass
>
>
> Extracted source (around line *#16*):
>
> 13:  			<%= f.label  :villain%>
> 14:  			<%= f.text_field :villain %><br /><br />
> 15:  			
> 16:  			<%= select_tag "issue", 
options_from_collection_for_select(@publisher, "id", "name") %>
> 17:  			<%=  %><br />
> 18:  			
> 19:  			<%= f.submit "Create the Issue", class: "btn btn-large btn-primary" %>
>
> Thanks,
>
> Steve
>
>
>