# Getting the reason why this fails?

**URL:** <https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818>\
**Category:** Rails\
**Created:** [January 29, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818 "2007-01-29T23:50:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 29, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818/1 "2007-01-29T23:50:12Z")

</div>

Hi there.

Have this code, and i need to find put why it fails.

> > Controller

* * *

## def update @user = User.find(@params[:id]) if @user.update\_attributes(@params[:user]) flash[:notice] = ‘The user was successfully updated.’ redirect\_to :action =\> ‘show’, :id =\> @user else flash[:notice] = “Error: The user have not been updated.” redirect\_to :action =\> ‘show’ end end

I have an array, that seem to be fine, and contains the correct  
information, how do i get the mysql error, that triggers the  
@user.update\_attributes to not be true. ??

- Emil

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 30, 2007, 12:50am UTC](https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818/2 "2007-01-30T00:50:15Z")

</div>

Are you receiving any specific message in the browser? If you are in  
development mode, you should see the error. You can also check your  
logs to see if there is more information there.

If you find any messages and are still unsure, please post them here.

Steve

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 30, 2007, 1:00am UTC](https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818/3 "2007-01-30T01:00:54Z")

</div>

I have checked my log, i have my Terminal running the script/server, and  
it responds the following:

* * *

## Processing UserController#update (for 127.0.0.1 at 2007-01-29 23:53:34) [POST] Session ID: b929e530ded93d3e6bfc66830dfd51a2 Parameters: {“user”=\>{“news\_edit”=\>“y”, “name”=\>“Emil T. Kampp”, “news\_delete”=\>“y”, “page\_create”=\>“y”, “zip”=\>“2700”, “country”=\>“EN”, “user\_all\_edit”=\>“y”, “page\_edit”=\>“y”, “news\_create”=\>“y”, “login”=\>“Emil”, “email”=\>“removed\_email\_address@domain.invalid”}, “commit”=\>“Update”, “action”=\>“update”, “change”=\>{“u”=\>“1”}, “id”=\>“1”, “controller”=\>“user”} User Load (0.002301) SELECT \* FROM users WHERE (users.id = ‘1’) LIMIT 1 SQL (0.000190) BEGIN SQL (0.000164) COMMIT Rendering within layouts/standard Rendering user/update Pages Load (0.001533) SELECT \* FROM pages WHERE (in\_menu = ‘true’) ORDER BY place\_in\_menu asc Pages Columns (0.002876) SHOW FIELDS FROM pages Pages Load (0.001068) SELECT \* FROM pages WHERE (controller = ‘user’) AND (action = ‘update’) ORDER BY place\_in\_menu asc LIMIT 1 Completed in 0.02136 (46 reqs/sec) | Rendering: 0.00951 (44%) | DB: 0.01188 (55%) | 200 OK [[http://localhost/user/update/1](http://localhost/user/update/1)] User Columns (0.003740) SHOW FIELDS FROM users

But this dosnt help me much, as i dont get the specific mysql error from  
this.

As i can se, tha thing that fails, is the @user.update\_attributes which  
should execute somkind of sql command, to update the table. But i cant  
find this mysql string, that ir runs, or the mysql error it should  
gennerate.

- Emil

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 30, 2007, 10:05am UTC](https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818/4 "2007-01-30T10:05:27Z")

</div>

It looks to me like it may be failing on validations rather than SQL  
as there is no update in the log.

Do you have any validations on your model? Are you also showing any  
errors in your update view?:  
\<%= error\_messages\_for(@user) %\>

update\_attributes does not directly run an SQL command. Any save or  
create command goes through a process before it actually executes SQL;  
most notably validations are checked and the call will return false  
if any fail.

Steve

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 30, 2007, 10:42pm UTC](https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818/5 "2007-01-30T22:42:59Z")

</div>

Stephen B. wrote:

> Do you have any validations on your model? Are you also showing any  
> errors in your update view?:  
> \<%= error\_messages\_for(@user) %\>
> 
> Steve

YES ! =)

This was just what i needed. I have now solved the puzzle, i needed to  
get some kind of error message, so i could locate the problem.

Thanx

---

<div class="post-metadata">

**Author:** ![emuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/96bed5/32.png) [@emuen](https://www.ruby-forum.com/u/emuen)\
**Post date:** [January 30, 2007, 2:12am UTC](https://www.ruby-forum.com/t/getting-the-reason-why-this-fails/83818/6 "2007-01-30T02:12:24Z")

</div>

Hi Emil,

Emil K. wrote:

> Have this code, and i need to find put why it fails.

It’s very difficult to help with nothing more than this. Perhaps you’d  
like  
to help us help you? Post your code. And maybe the error message(s)  
you’re  
getting.

Bill
