# Object.save is not creating an insert statement

**URL:** <https://www.ruby-forum.com/t/object-save-is-not-creating-an-insert-statement/78759>\
**Category:** Rails\
**Created:** [March 8, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/object-save-is-not-creating-an-insert-statement/78759 "2006-03-08T23:23:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Stackhouse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@John\_Stackhouse](https://www.ruby-forum.com/u/John_Stackhouse)\
**Post date:** [March 8, 2006, 11:23pm UTC](https://www.ruby-forum.com/t/object-save-is-not-creating-an-insert-statement/78759/1 "2006-03-08T23:23:11Z")

</div>

I have a model for a task class. When I try to save a task, for some  
reason no INSERT statement is being generated. Here’s the pertinent  
part of the

## development.log:

Processing TasksController#create\_fromProject (for 70.247.24.238 at  
2006-03-08 14:20:30) [POST]  
Parameters: {“commit”=\>“Create”, “action”=\>“create\_fromProject”,  
“task”=\>{…blahblahblah…}, “id”=\>“3”, “controller”=\>“tasks”}  
Task Columns (0.000345) SHOW FIELDS FROM tasks  
SQL (0.000133) BEGIN  
SQL (0.000124) COMMIT  
Redirected to …

## And the code in the task controller:

def create\_fromProject  
@task = Task.new(params[:task])  
if @task.save  
flash[:notice] = ‘Task was successfully created.’  
redirect\_to :action =\> ‘list’  
else  
render :action =\> ‘new’  
end  
end

So what’s the deal?

Thanks!

---

<div class="post-metadata">

**Author:** ![John\_Stackhouse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@John\_Stackhouse](https://www.ruby-forum.com/u/John_Stackhouse)\
**Post date:** [March 9, 2006, 10:35am UTC](https://www.ruby-forum.com/t/object-save-is-not-creating-an-insert-statement/78759/2 "2006-03-09T10:35:23Z")

</div>

Am Mittwoch, den 08.03.2006, 23:23 +0100 schrieb John Stackhouse:

> “task”=\>{…blahblahblah…}, “id”=\>“3”, “controller”=\>“tasks”}  
> if @task.save  
> flash[:notice] = ‘Task was successfully created.’  
> redirect\_to :action =\> ‘list’  
> else  
> render :action =\> ‘new’  
> end  
> end
> 
> So what’s the deal?

Seems to look ok for me. Perhaps the problem is in your model code.

–  
Norman T.

[http://blog.inlet-media.de](http://blog.inlet-media.de)

---

<div class="post-metadata">

**Author:** ![John\_Stackhouse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@John\_Stackhouse](https://www.ruby-forum.com/u/John_Stackhouse)\
**Post date:** [March 9, 2006, 10:38am UTC](https://www.ruby-forum.com/t/object-save-is-not-creating-an-insert-statement/78759/3 "2006-03-09T10:38:26Z")

</div>

The data you are passing to the task object might be failing some of the  
validation you set up in the model.

---

<div class="post-metadata">

**Author:** ![John\_Stackhouse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@John\_Stackhouse](https://www.ruby-forum.com/u/John_Stackhouse)\
**Post date:** [March 9, 2006, 10:47am UTC](https://www.ruby-forum.com/t/object-save-is-not-creating-an-insert-statement/78759/4 "2006-03-09T10:47:46Z")

</div>

Am Donnerstag, den 09.03.2006, 09:37 +0000 schrieb Kamal F.:

> > Task Columns (0.000345) SHOW FIELDS FROM tasks  
> > flash[:notice] = ‘Task was successfully created.’  
> > redirect\_to :action =\> ‘list’  
> > else  
> > render :action =\> ‘new’  
> > end  
> > end

But if, there should not be a redirection.

–  
Norman T.

[http://blog.inlet-media.de](http://blog.inlet-media.de)

---

<div class="post-metadata">

**Author:** ![John\_Stackhouse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@John\_Stackhouse](https://www.ruby-forum.com/u/John_Stackhouse)\
**Post date:** [March 9, 2006, 11:39am UTC](https://www.ruby-forum.com/t/object-save-is-not-creating-an-insert-statement/78759/5 "2006-03-09T11:39:17Z")

</div>

Norman T. wrote:

> But if, there should not be a redirection.

Yes. Perhaps a before\_save method is returning false.

–  
We develop, watch us RoR, in numbers too big to ignore.
