# Object not saving but no error message displayed

**URL:** <https://www.ruby-forum.com/t/object-not-saving-but-no-error-message-displayed/132911>\
**Category:** Rails\
**Created:** [March 25, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/object-not-saving-but-no-error-message-displayed/132911 "2008-03-25T19:05:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 25, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/object-not-saving-but-no-error-message-displayed/132911/1 "2008-03-25T19:05:57Z")

</div>

Hi. I have a form in my app which, for some reason is not saving any  
objects to the database. After clicking submit it redirects back to  
itself, but it dosent give any information as to what is going wrong.

Here is the info from development.log,

Processing AuctionsController#create (for 127.0.0.1 at 2008-03-25  
18:01:56) [POST]  
Session ID: cbfe7affee5e55448c284a1e488f7b17  
Parameters: {“commit”=\>“Create”, “action”=\>“create”,  
“controller”=\>“auctions”, “auction”=\>{“price”=\>“5”, “title”=\>“test  
title”, “category\_id”=\>“2”, “description”=\>“test description”,  
“user\_id”=\>“1”,  
“uploaded\_picture”=\>#ActionController::UploadedStringIO:0x51bbd18}}  
e[4;35;1mCategory Load (0.001000)e[0m e[0mSELECT \* FROM categories  
e[0m  
Rendering template within layouts/orangeblue  
Rendering auctions/new  
Rendered shared/\_search (0.00300)  
Rendered shared/\_menubar (0.00300)  
Rendered shared/\_loginside (0.00200)  
Rendered shared/\_itemsuwatchside (0.00200)  
Completed in 0.07300 (13 reqs/sec) | Rendering: 0.02800 (38%) | DB:  
0.00100 (1%) | 200 OK [[http://localhost/auctions](http://localhost/auctions)]

Any help would be appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 25, 2008, 7:33pm UTC](https://www.ruby-forum.com/t/object-not-saving-but-no-error-message-displayed/132911/2 "2008-03-25T19:33:19Z")

</div>

Dan S. wrote:

> Hi. I have a form in my app which, for some reason is not saving any  
> objects to the database. After clicking submit it redirects back to  
> itself, but it dosent give any information as to what is going wrong.

We would need to see the code for your ‘create’ action in your  
auctions\_controller.rb

–  
[http://www.5valleys.com/](http://www.5valleys.com/)

[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 25, 2008, 7:48pm UTC](https://www.ruby-forum.com/t/object-not-saving-but-no-error-message-displayed/132911/3 "2008-03-25T19:48:01Z")

</div>

Auction controller:

def create  
@cats = Category.find(:all)  
params[:auction][:user\_id] = current\_user.id  
@auction = Auction.new(params[:auction])

```
respond_to do |format|
  if @auction.save
    flash[:notice] = 'Auction was successfully created.'
    format.html { redirect_to(@auction) }
    format.xml { render :xml => @auction, :status => :created, 

```

:location =\> @auction }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @auction.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

I also have an items controller, with a create action which is pretty  
much identical, but works just fine.

Item controller:

def create  
@cats = Category.find(:all)  
params[:item][:user\_id] = current\_user.id  
@item = Item.new(params[:item])

```
respond_to do |format|
  if @item.save
    flash[:notice] = 'Item was successfully created.'
    format.html { redirect_to(@item) }
    format.xml { render :xml => @item, :status => :created, 

```

:location =\> @item }  
else  
format.html { render :action =\> “new” }  
format.xml { render :xml =\> @item.errors, :status =\>  
:unprocessable\_entity }  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![drsharp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e9bcb4/32.png) [@drsharp](https://www.ruby-forum.com/u/drsharp)\
**Post date:** [March 25, 2008, 8:01pm UTC](https://www.ruby-forum.com/t/object-not-saving-but-no-error-message-displayed/132911/4 "2008-03-25T20:01:08Z")

</div>

Dan S. wrote:

> ```
> format.html { redirect_to(@auction) }
> 
> ```
> 
> I also have an items controller, with a create action which is pretty  
> if @item.save  
> end

Everything looks good there. You said it’s redirecting back on itself.  
I assume you mean that it’s going back to the ‘new’ action, which is  
what you have it doing if the save fails (which is good). So, make sure  
you have the following in your new.html.erb file…

\<%= error\_messages\_for :auction %\>

That should hopefully give you a hint why the save is failing. Probably  
some validations you have setup that aren’t passing.

–  
[http://www.5valleys.com/](http://www.5valleys.com/)

[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)
