# Having troubles saving a new model

**URL:** <https://www.ruby-forum.com/t/having-troubles-saving-a-new-model/158250>\
**Category:** Rails\
**Created:** [January 21, 2009, 2:51am UTC](https://www.ruby-forum.com/t/having-troubles-saving-a-new-model/158250 "2009-01-21T02:51:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dazonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba8739/32.png) [@dazonic](https://www.ruby-forum.com/u/dazonic)\
**Post date:** [January 21, 2009, 2:51am UTC](https://www.ruby-forum.com/t/having-troubles-saving-a-new-model/158250/1 "2009-01-21T02:51:36Z")

</div>

My model is being created but isn’t saving. It’s like it skips straight  
past saving. Any ideas why it might do this? Updating works fine.

def create  
@volunteer = Volunteer.new(params[:volunteer])  
@volunteer.save  
redirect\_to(volunteers\_url)  
end

And here’s what the console reads upon create:

Processing VolunteersController#create (for 127.0.0.1 at 2009-01-21  
11:33:00) [POST]  
Parameters: {“commit”=\>“Create”, “volunteer”=\>{“name”=\>“test”,  
“job\_id”=\>“2”, “accepted”=\>“0”, “start\_time(1i)”=\>“2009”,  
“finish\_time(1i)”=\>“2009”, “start\_time(2i)”=\>“1”,  
“finish\_time(2i)”=\>“1”, “start\_time(3i)”=\>“21”, “role”=\>“Team Leader”,  
“finish\_time(3i)”=\>“21”, “start\_time(4i)”=\>“01”,  
“finish\_time(4i)”=\>“01”, “start\_time(5i)”=\>“18”,  
“finish\_time(5i)”=\>“18”, “email”=\>“removed\_email\_address@domain.invalid”},  
“authenticity\_token”=\>“1a745e26f1bf45dd1a1bf15f45b29da69e4b8a15”}  
Redirected to [http://volunteers.local/volunteers](http://volunteers.local/volunteers)  
Completed in 14ms (DB: 0) | 302 Found  
[[http://volunteers.local/volunteers](http://volunteers.local/volunteers)]

---

<div class="post-metadata">

**Author:** ![dazonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba8739/32.png) [@dazonic](https://www.ruby-forum.com/u/dazonic)\
**Post date:** [January 21, 2009, 3:31am UTC](https://www.ruby-forum.com/t/having-troubles-saving-a-new-model/158250/2 "2009-01-21T03:31:59Z")

</div>

On Tue, Jan 20, 2009 at 8:51 PM, Darren J. \<  
removed\_email\_address@domain.invalid\> wrote:

> #save returns true if successful, false otherwise. The code generated by  
> the scaffold typically looks something like:

```
  if @volunteer.save
    flash[:notice] = "New volunteer successfully added to database."
    format.html { redirect_to(volunteers_url) }
    format.xml { render :xml => @volunteer, :status => :created,

```

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

Your volunteer model is probably failing a validation or two. Try  
looking  
in your development log.

–wpd

---

<div class="post-metadata">

**Author:** ![dazonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba8739/32.png) [@dazonic](https://www.ruby-forum.com/u/dazonic)\
**Post date:** [January 21, 2009, 3:51am UTC](https://www.ruby-forum.com/t/having-troubles-saving-a-new-model/158250/3 "2009-01-21T03:51:58Z")

</div>

Hi, thanks Patrick.

I originally did have that scaffold type setup and it kept returning  
false so I forced it to save just to show it’s not working.

I don’t have any validations on my model at the moment and sorry, I  
should have said, that console excerpt is straight from the development  
log, it’s not showing any errors which is why I’m a bit lost.

---

<div class="post-metadata">

**Author:** ![dazonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba8739/32.png) [@dazonic](https://www.ruby-forum.com/u/dazonic)\
**Post date:** [January 21, 2009, 6:23am UTC](https://www.ruby-forum.com/t/having-troubles-saving-a-new-model/158250/4 "2009-01-21T06:23:29Z")

</div>

Try firing up script/console and manually try making a new Volunteer  
object and saving it.

script/console

> > a = Volunteer.new(:name =\> “john”) # shouldn’t matter if you don’t pass all the fields since there are no validations  
> > a.save.

Might not answer your question, but should help you figure out where  
the issue is.

On Jan 20, 8:51 pm, Darren J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![dazonic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba8739/32.png) [@dazonic](https://www.ruby-forum.com/u/dazonic)\
**Post date:** [January 21, 2009, 8:03am UTC](https://www.ruby-forum.com/t/having-troubles-saving-a-new-model/158250/5 "2009-01-21T08:03:34Z")

</div>

> Try firing up script/console and manually try making a new Volunteer  
> object and saving it.

Hmm… yep, that’s returning false.

I found where the problem lies, thanks everyone. a dodgy before\_save  
filter I made.
