# Update command not updating DB

**URL:** <https://www.ruby-forum.com/t/update-command-not-updating-db/51594>\
**Category:** Rails\
**Created:** [January 4, 2006, 12:41am UTC](https://www.ruby-forum.com/t/update-command-not-updating-db/51594 "2006-01-04T00:41:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [January 4, 2006, 12:41am UTC](https://www.ruby-forum.com/t/update-command-not-updating-db/51594/1 "2006-01-04T00:41:27Z")

</div>

I really need your help guys… I spent 6 hours on this simple update  
command today that should work. It works fine in my other controller,  
but doesn’t work in this one for some reason.

Here is my controller code for the list view, and then the update  
command:

======  
def edit  
@user = User.find(params[:id])  
end

def update  
@user = User.find(params[:id])

```
if @user.update_attributes(@params[:users])
  redirect_to(:action => "save_account")
else
  flash[:notice] = "Couldn't save account information, please try 

```

# again." redirect\_to(:action =\> ‘edit’, :id =\> @user.id) end end

if I set up a template for update and inspect both @user and  
params[:user] this is what I get, in that same order:

======  
#“test s address”, “shipping\_state”=\>“te”, “billing\_street”=\>“16409”,  
“billing\_city”=\>“test”, “website”=\>“[www.test.com](http://www.test.com)”,  
“shipping\_country”=\>“test”, “shipping\_zip”=\>“test”, “id”=\>“51”,  
“shipping\_city”=\>“test”, “shipping\_option”=\>“1”, “billing\_state”=\>“te”,  
“phone”=\>“tttttttest”, “billing\_country”=\>“test”, “billing\_zip”=\>“test”,  
“studio\_name”=\>“test studio”, “shipping\_street”=\>“test”,  
“password”=\>“4f939b7b470595d4c9924342ad57821cc818deac”, “login”=\>“test”,  
“email”=\>“removed\_email\_address@domain.invalid”}\>

* * *

# {“shipping\_state”=\>“te”, “studio\_address”=\>“test s address”, “billing\_street”=\>“testing”, “billing\_city”=\>“test”, “website”=\>“[www.test.com](http://www.test.com)”, “shipping\_zip”=\>“test”, “shipping\_country”=\>“test”, “billing\_state”=\>“te”, “shipping\_city”=\>“test”, “shipping\_option”=\>“1”, “phone”=\>“tttttttest”, “billing\_country”=\>“test”, “billing\_zip”=\>“test”, “studio\_name”=\>“test studio”, “shipping\_street”=\>“test”}

Why is it that my @user starts with a # and never tells it that the  
“test s address” is the studio address? Also, why does it end with }\>? I  
think my @user variable is why my .update\_attributes command is failing  
and never telling the SQL server to update itself. You will notice that  
in my params I don’t include password, login, or email… but that is  
because this is just editing user info and I don’t want re-access to  
that info. Can someone please help me. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [January 4, 2006, 1:25am UTC](https://www.ruby-forum.com/t/update-command-not-updating-db/51594/2 "2006-01-04T01:25:31Z")

</div>

Bryan C. wrote:

> ```
> if @user.update_attributes(@params[:users])
> 
> ```

Perhaps your problem is that you’re using @params here  
rather than the params method which can handle both  
symbol and string keys.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [January 4, 2006, 3:58am UTC](https://www.ruby-forum.com/t/update-command-not-updating-db/51594/3 "2006-01-04T03:58:15Z")

</div>

On 1/3/06, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > if @user.update_attributes(@params[:users])
> > 
> > ```

Is it just a typo that you are referencing @params[:users] here and  
@params[:user] elsewhere in your message?

---

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [January 4, 2006, 3:49am UTC](https://www.ruby-forum.com/t/update-command-not-updating-db/51594/4 "2006-01-04T03:49:27Z")

</div>

Mark Reginald J. wrote:

> Bryan C. wrote:
> 
> > ```
> > if @user.update_attributes(@params[:users])
> > 
> > ```
> 
> Perhaps your problem is that you’re using @params here  
> rather than the params method which can handle both  
> symbol and string keys.
> 
> –  
> We develop, watch us RoR, in numbers too big to ignore.

I have used @params[:user], @params[“users”], and params[:users]… each  
to no avail. Anyone?

---

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [January 4, 2006, 4:28am UTC](https://www.ruby-forum.com/t/update-command-not-updating-db/51594/5 "2006-01-04T04:28:42Z")

</div>

Lance B. wrote:

> On 1/3/06, Mark Reginald J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > ```
> > > if @user.update_attributes(@params[:users])
> > > 
> > > ```
> 
> Is it just a typo that you are referencing @params[:users] here and  
> @params[:user] elsewhere in your message?

Yes, just a typo, sorry.

---

<div class="post-metadata">

**Author:** ![mrpunkin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@mrpunkin](https://www.ruby-forum.com/u/mrpunkin)\
**Post date:** [January 6, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/update-command-not-updating-db/51594/6 "2006-01-06T21:40:06Z")

</div>

Bryan C. wrote:

> end  
> end  
> “shipping\_city”=\>“test”, “shipping\_option”=\>“1”, “billing\_state”=\>“te”,  
> “shipping\_country”=\>“test”, “billing\_state”=\>“te”,  
> because this is just editing user info and I don’t want re-access to  
> that info. Can someone please help me. Thanks a lot.

Look carefully at where you put your inspecting code in the template -  
it looks to me as if it was inside an HTML helper call, so that the part  
up to the first =\> in the @user was hidden inside the tag, and you have  
ended up with }\> in the content.

Doing View Source in the browser might help you to diagnose this.

regards

Justin
