# Problem updating data

**URL:** <https://www.ruby-forum.com/t/problem-updating-data/226039>\
**Category:** Rails\
**Created:** [April 19, 2009, 10:59pm UTC](https://www.ruby-forum.com/t/problem-updating-data/226039 "2009-04-19T22:59:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ps\_gem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ac8455/32.png) [@ps\_gem](https://www.ruby-forum.com/u/ps_gem)\
**Post date:** [April 19, 2009, 10:59pm UTC](https://www.ruby-forum.com/t/problem-updating-data/226039/1 "2009-04-19T22:59:17Z")

</div>

## It may be my stupid mistake; when I try to update users profile data it doesn’t update or give any error. Any help would be greatly appreciated. Thanks

## my users\_controller.rb file:

def edit\_userprofile  
@olduserprofile= User.find(session[:user\_id])  
end

def save\_userprofile  
@newprofile = User.new(params[:newuserprofile])  
@upuser=User.find(params[:id])  
@upuser.name = @newprofile.name  
@upuser.phone = @newprofile.phone  
@upuser.address = @newprofile.address  
@upuser.email = @newprofile.email  
@upuser.save  
redirect\_to :action =\> :edit\_userprofile;  
flash.now[:notice] = “Your profile has been edited sucessfully”  
end

* * *

## edit\_profile.rhtml:

\<%= “edit\_userprofile” %\>

Edit User

 \<% form\_for :newuserprofile, :url =\> { :action =\> 'save\_userprofile', :id=\>@olduserprofile} do|form|%\>

```
  <div class="formlabel"><label for="user_name">Name:</label></div>
  <div class="forminput"><%= form.text_field :name, :size =>

```

40,:value =\> @olduserprofile.name %\>

```
  <div class="formlabel"><label

```

for=“user\_address”\>Address:

  

\<%= form.text\_field :address, :size =\>  
40,:value =\> @olduserprofile.address %\>

```
  <div class="formlabel"><label

```

for=“user\_phone”\>Phone:

\<%= form.text\_field :phone, :size =\> 40  
,:value =\> @olduserprofile.phone %\>

```
  <div class="formlabel"><label

```

for=“user\_email”\>Email:

\<%= form.text\_field :email, :size =\> 40  
,:value =\> @olduserprofile.email %\>

```
  <div class="formlabel">&nbsp;</div>
  <div class="forminput"><td colspan="2"><%= submit_tag "Edit

```

profile", :class =\> “submit” %\>

&nbsp;

```
<% end %>

```

---

<div class="post-metadata">

**Author:** ![ps\_gem](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ac8455/32.png) [@ps\_gem](https://www.ruby-forum.com/u/ps_gem)\
**Post date:** [April 21, 2009, 2:48pm UTC](https://www.ruby-forum.com/t/problem-updating-data/226039/2 "2009-04-21T14:48:58Z")

</div>

The user data are invalid.  
Replace “@upuser.save” with “@upuser.save!”,  
then it will raise an exception,  
so you will know what’s the problem.

Dmitry
