Forum: Ruby on Rails NoMethodError (undefined method `call' for nil:NilClass):

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jigu (Guest)
on 2009-03-20 11:31
(Received via mailing list)
I am getting HTTP 500 Internal server error when updating info for one
of page of my website. Please help me and for your reference i have
posted ruby trace below:

Processing ModelsController#update (for 203.187.233.94 at 2009-03-20
02:40:06) [PUT]
  Session ID:
BAh7CDoMY3NyZl9pZCIlYTc0NDc5OWI1ZDNhMDM4YmVjZTY0YjE3NGZkODQ2
YjAiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
c2h7AAY6CkB1c2VkewA6DHVzZXJfaWRpBw==--0cc7b78313f817b2be3cc19a19164dbfa9a351e9
  Parameters: {"commit"=>"Update", "action"=>"update",
"_method"=>"put",
"authenticity_token"=>"47bc4f13abf32c82e7602e1ebd52f5a5338a566d",
"id"=>"12", "controller"=>"admin/models", "model"=>{"city"=>"Surat",
"biography"=>"", "measurements"=>"", "weight"=>"110",
"agency_rep_email"=>"", "agency_address"=>"", "country_id"=>"1",
"approved"=>"0", "agency_name"=>"", "region_id"=>"1", "sex"=>"m",
"agency_rep_name"=>"", "height"=>"5'3", "first_name"=>"Jignesh",
"agency_phone"=>"", "eye_color_id"=>"3", "hair_color_id"=>"9",
"age"=>"30", "last_name"=>"Wadia"}}


NoMethodError (undefined method `call' for nil:NilClass):
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/mime_responds.rb:156:in `respond'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/mime_responds.rb:154:in `each'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/mime_responds.rb:154:in `respond'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/mime_responds.rb:107:in `respond_to'
    /app/controllers/admin/models_controller.rb:64:in `update'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:1162:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:1162:in `perform_action_without_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/filters.rb:580:in `call_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/filters.rb:573:in `perform_action_without_benchmark'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
    /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/rescue.rb:201:in `perform_action_without_caching'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/caching/sql_cache.rb:13:in `perform_action'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/connection_adapters/abstract/query_cache.rb:33:in
`cache'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/
active_record/query_cache.rb:8:in `cache'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/caching/sql_cache.rb:12:in `perform_action'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:529:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:529:in `process_without_filters'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/filters.rb:569:in
`process_without_session_management_support'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/session_management.rb:130:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/base.rb:389:in `process'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:149:in `handle_request'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:107:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:104:in `synchronize'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:104:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:120:in `dispatch_cgi'
    /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/dispatcher.rb:35:in `dispatch'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
103:in `process_request'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
153:in `with_signal_handler'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
101:in `process_request'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
78:in `process_each_request'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:612:in
`each_cgi'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in
`each'
    /usr/local/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in
`each_cgi'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
77:in `process_each_request'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
76:in `catch'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
76:in `process_each_request'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
50:in `process!'
    /usr/local/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/fcgi_handler.rb:
24:in `process!'
    dispatch.fcgi:24

Rendering /home/canadian/canadianmodelscouts.com/public/500.html (500
Internal Server Error)


REgs,
Jignesh W.
"Wolas!" (Guest)
on 2009-03-20 12:36
(Received via mailing list)
it would be a good idea to post the controller method update and the
class Model.
Jignesh W. (Guest)
on 2009-03-20 14:00
"Wolas!" wrote:
> it would be a good idea to post the controller method update and the
> class Model.

But how can I fix that error message? Database information is updating
properly but page is redirecting to HTTP 500 Internal server error page
and I am unable to fix this error. Please help me how can i fix it. I am
using code below to be updating model entry... and same code works
properly for other modules.

  # PUT /models/1
  # PUT /models/1.xml
  def update
    @model = Model.find(params[:id], :include=>:user)

    respond_to do |format|
      if @model.update_attributes(params[:model])
        @model.user.roles.clear
  @model.user.roles << Role.find_or_create_by_name("model")
        #flash[:notice] = "Model was successfully updated."
        #format.html { redirect_to([:admin, @model]) }
        #format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @model.errors, :status =>
:unprocessable_entity }
      end
    end
  end
Frederick C. (Guest)
on 2009-03-20 16:12
(Received via mailing list)
On Mar 20, 12:00 pm, Jignesh W. <removed_email_address@domain.invalid>
wrote:
>
>     respond_to do |format|
>       if @model.update_attributes(params[:model])
>         @model.user.roles.clear
>   @model.user.roles << Role.find_or_create_by_name("model")
>         #flash[:notice] = "Model was successfully updated."
>         #format.html { redirect_to([:admin, @model]) }
>         #format.xml  { head :ok }

in this branch you're not telling rails what to do - you've commented
out all your format.bla calls

Fred
Jignesh W. (Guest)
on 2009-03-21 08:00
Frederick C. wrote:
> On Mar 20, 12:00�pm, Jignesh W. <removed_email_address@domain.invalid>
> wrote:
>>
>> � � respond_to do |format|
>> � � � if @model.update_attributes(params[:model])
>> � � � � @model.user.roles.clear
>> � @model.user.roles << Role.find_or_create_by_name("model")
>> � � � � #flash[:notice] = "Model was successfully updated."
>> � � � � #format.html { redirect_to([:admin, @model]) }
>> � � � � #format.xml �{ head :ok }
>
> in this branch you're not telling rails what to do - you've commented
> out all your format.bla calls
>
> Fred

Okay now I have activated commented statements but still I am getting
same error message ane redirecting to 505 error page.

Jignesh W.
Phillip (Guest)
on 2009-03-21 15:27
(Received via mailing list)
When running database queries from form input, I usually change params
[foo][id] to an integer. Everything passed with the request object is
of type "string" and will return a nil object in Ruby.

Model.find(params[foo][id].to_i)

On Mar 21, 2:00 am, Jignesh W. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.