# Can not update my data base using "update\_attributes"

**URL:** <https://www.ruby-forum.com/t/can-not-update-my-data-base-using-update-attributes/128766>\
**Category:** Engines\
**Created:** [February 11, 2008, 11:56am UTC](https://www.ruby-forum.com/t/can-not-update-my-data-base-using-update-attributes/128766 "2008-02-11T11:56:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [February 11, 2008, 11:56am UTC](https://www.ruby-forum.com/t/can-not-update-my-data-base-using-update-attributes/128766/1 "2008-02-11T11:56:15Z")

</div>

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:in`update’

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:in`update’  
/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:in`perform\_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:in`perform\_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:in`measure’  
/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:in`perform\_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:in`cache’  
/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:in`perform\_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:in`process\_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:in`process’  
/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:in`handle\_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:in`dispatch\_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:in`process’  
/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:in`process’  
/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:in`each’  
/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:in`run’  
/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:in`new’  
/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:in`initialize’  
/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:in`run’  
/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:in`each’  
/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:in`run’  
/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)

---

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [October 10, 2008, 9:43pm UTC](https://www.ruby-forum.com/t/can-not-update-my-data-base-using-update-attributes/128766/2 "2008-10-10T21:43:31Z")

</div>

> 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:in`update’
> 
> 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 🙂

-=R

---

<div class="post-metadata">

**Author:** ![sshefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d9b06d/32.png) [@sshefer](https://www.ruby-forum.com/u/sshefer)\
**Post date:** [October 19, 2008, 11:52am UTC](https://www.ruby-forum.com/t/can-not-update-my-data-base-using-update-attributes/128766/3 "2008-10-19T11:52:35Z")

</div>

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’.
