Can not update my data base using "update_attributes"


#1

Hello,

I have this problem that my rails application works fine in development
environment on my local Linux and windows system but when I uploaded it
to work on the server in production environment I have this problem as
listed in the pasted log file at the end of this entry:
NoMethodError (undefined method []' for nil:NilClass): /app/controllers/admin_controller.rb:201:inupdate’

the support team could not crack this one. I would think that the method
“update_attributes” would just work. if I enter a new entry to the data
base “mysql” it works fine and also the sort works fine in updating the
data base.
I have attached the controller file. all the functions work except for
the update one and only when it is running on the hosting server under
production environment.

I do not understand why it says in the log file nilclass when the return
@params is not nil.

Hope someone can help me on this one.


********* controller *******************


def update
if session[:project_cat].nil? then
redirect_to :action => ‘index’
else
@category = Parent.find_by_cat_name(session[:project_cat])
if @category.cat_name == “branding” then
@project = @category.brandings.find(params[:id])
elsif @category.cat_name == “client_say” then
@project = @category.client_says.find(params[:id])
else
@project = @category.projects.find(params[:id])
end

if @project.update_attributes(@params[:project]) # this is line 201
flash[:notice] = ‘Project was successfully updated.’
redirect_to :action => ‘show’, :id => @project, :cat_name =>
@category.id
else
render :action => ‘edit’, :cat_name => @category.id
end
end
end


***** log file *************************


Processing AdminController#update (for 81.3.100.245 at 2008-02-07
05:22:08) [POST]
Session ID:
BAh7CjoWcHJvamVjdF9pbWFnZV91cmx7ADoQcHJvamVjdF9jYXQiCW1pc2M6%0ACXVzZXJpBzoOcmV0dXJuX3RvMCIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxl%0Acjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D–be44b352117c1f931fe6eb0eab2a7f0b99ab8edd
Parameters: {“commit”=>“Save”, “cat_name”=>“3”,
“project”=>{“tags”=>“flash private”, “client”=>“Mom & Dad”,
“description”=>“A movie clip for my parent’s 35 anniversary”,
“url_link”=>""}, “action”=>“update”, “id”=>“25”, “controller”=>“admin”}

NoMethodError (undefined method []' for nil:NilClass): /app/controllers/admin_controller.rb:201:inupdate’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in
send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:inperform_action_without_filters’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in
call_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:inperform_action_without_benchmark’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in
perform_action_without_rescue' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:inperform_action_without_caching’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:678:in
perform_action' /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/query_cache.rb:33:incache’
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/query_cache.rb:8:in
cache' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:inperform_action’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:in
send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:524:inprocess_without_filters’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:685:in
process_without_session_management_support' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/session_management.rb:123:inprocess’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:388:in
process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:inhandle_request’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in
dispatch' /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:indispatch_cgi’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in
dispatch' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel/rails.rb:76:inprocess’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel/rails.rb:74:in
synchronize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel/rails.rb:74:inprocess’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel.rb:159:in
process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel.rb:158:ineach’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel.rb:158:in
process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel.rb:285:inrun’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel.rb:285:in
initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel.rb:285:innew’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel.rb:285:in
run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel.rb:268:ininitialize’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel.rb:268:in
new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel.rb:268:inrun’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel/configurator.rb:282:in
run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/../lib/mongrel/configurator.rb:281:ineach’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel/configurator.rb:281:in
run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/mongrel_rails:128:inrun’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/…/lib/mongrel/command.rb:212:in
`run’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.3/bin/mongrel_rails:281

Rendering /home/saydigi/saydigitaldesign/public/500.html (500 Internal
Server Error)


#2

I have this problem that my rails application works fine in development
environment on my local Linux and windows system but when I uploaded it
to work on the server in production environment I have this problem as
listed in the pasted log file at the end of this entry:
NoMethodError (undefined method []' for nil:NilClass): /app/controllers/admin_controller.rb:201:inupdate’

the support team could not crack this one. I would think that the method
“update_attributes” would just work.

For me a similar error was: with update_attributes it runs all
‘before_save’ filters before actually updating–I had a filter that was
nuking the very attribute I was trying to change [by calling reload]. Go
figure :slight_smile:

-=R


#3

Shai Sayfanaltman wrote:

if @project.update_attributes(@params[:project]) # this is line 201

Hey Shai,
Use params as a local variable, not as an instance variable; ‘params’
instead of ‘@params’.