Forum: Ruby on Rails Having troubles saving a new model

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Darren J. (Guest)
on 2009-01-21 03:51
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])

And here's what the console reads upon create:

Processing VolunteersController#create (for 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"},
Redirected to http://volunteers.local/volunteers
Completed in 14ms (DB: 0) | 302 Found
Patrick D. (Guest)
on 2009-01-21 04:31
(Received via mailing list)
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:

        flash[:notice] = "New volunteer successfully added to database."
        format.html { redirect_to(volunteers_url) }
        format.xml  { render :xml => @volunteer, :status => :created,
:location => @volunteer }
        format.html { render :action => "new" }
        format.xml  { render :xml => @volunteer.errors, :status =>
:unprocessable_entity }

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

Darren J. (Guest)
on 2009-01-21 04:51
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.
John Y. (Guest)
on 2009-01-21 07:23
(Received via mailing list)
Try firing up script/console and manually try making a new Volunteer
object and saving it.


>> a = => "john") # shouldn't matter if you don't pass all the fields 
since there are no validations

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>
Darren J. (Guest)
on 2009-01-21 09:03
> 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.
This topic is locked and can not be replied to.