JohnMerlino
JohnMerlino

Reputation: 3928

nil object error

Here's the output:

 Parameters: {"action"=>"confirm", "id"=>"1", "controller"=>"sites"}
 User Columns (2.2ms)   SHOW FIELDS FROM `users`
 User Load (0.3ms)   SELECT * FROM `users` WHERE (`users`.`id` = 2) LIMIT 1
 School Load (0.3ms)   SELECT * FROM `schools` LIMIT 1
 Rendering template within layouts/application
 Rendering sites/confirm

ActionView::TemplateError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.map) on line #4 of app/views/sites/confirm.erb:
 1: 
 2:  <%   
 3:    form_for(:site, :url => {:action => :confirm}) do 
 4:    select_tag(:id, options_from_collection_for_select(@confirm, 'id', 'confirm')) 
 5:    end
 6:   %>

Even when I did: @confirm = Request.find(:all) in controller, it still returned the error.

Sites Controller:

def confirm
x = current_user.contact.contactable
@confirm = Request.find(:all, :conditions => ["location_id = ?", x])
end

Confirm view in sites folder:

<%   
form_for(:site, :url => {:action => :confirm}) do 
select_tag(:id, options_from_collection_for_select(@confirm, 'id', 'confirm')) 
end
%>

Any idea why? Error occurs on line 4. I believe it thinks @confirm is not an array, although it should be because in controller I pass two items from table into it. I made the options_from_collection_for_select options similar to the one in the rails guide. Basically, I want to show a list of options to select from based on whether those options match the location of the current user. Thanks for any suggestions.

Upvotes: 0

Views: 531

Answers (2)

Mike AC7RV
Mike AC7RV

Reputation: 11

Is the action after the 'private' keyword in your controller?

I realize this is a late post to an old thread. Here's hoping that it helps either the Original Poster or anyone else having this problem.

Upvotes: 1

John Topley
John Topley

Reputation: 115292

The error is implying that the @confirm instance variable within your controller's confirm method is nil. Can you add some logging to verify if this is the case or not?


Edit: I've just noticed that your form_for block as posted in the question uses:

<%= form_for ... %>

When it should be:

<% form_for ... %>

Upvotes: 1

Related Questions