views:

78

answers:

2

This is the line it lands on.

@object = Object.find(params[:id]) 

    respond_to do |format|
       if @object.update_attributes(:status=>Object::PUBLISHED, :published_at => Time.now)
         format.html { redirect_to :action => :publish_detail }
         format.xml  { head :ok }
         format.json { head :ok }
  #else
  #  flash[:error] = 'There was a problem updating your object.'
  #  format.html { redirect_to :action => "publish_detail" }
  #  format.xml  { render :xml => @object.errors, :status => :unprocessable_entity }
  #  format.json { render :json => @object.errors, :status => :unprocessable_entity }
  end
end

and the stack trace

/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/whiny_nil.rb:52:in `method_missing'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:175:in `respond'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:173:in `each'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:173:in `respond'
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.8/lib/action_controller/mime_responds.rb:107:in `respond_to'
.../app/controllers/objects_controller.rb:252:in `publish'

why would i get an error there?

I added

puts "||||||||||||||||||#{@object.name}"

and the console shows that the object isn't nil.. =\

The log shows:

NoMethodError (undefined method `call' for nil:NilClass):
  app/controllers/objects_controller.rb:252:in `publish'

Rendered rescues/_trace (26.1ms)
Rendered rescues/_request_and_response (1.1ms)
Rendering rescues/layout (internal_server_error)
+2  A: 

It means... uh... that you are trying to call the "call" method on a "nil" object.

This happens when you use an object thinking it should be vaild, that is instead nil. This can be the case e.g. if Object.find cannot find the object and returns "nil".

@object will then be "nil" and you cannot treat it as if it was of type Object.

EDIT: always check using "nil?" before using an object that is of uncertain provenience.

baol
A: 

As it turns out, this error was happening because (in rails 2.3.8) i guess you can't set a datetime with a date_select.

So I changed my f.date_select to a f.datetime_select and re-saved the date, and all was well.

DerNalia