# Newbie question: persisting an object

**URL:** <https://www.ruby-forum.com/t/newbie-question-persisting-an-object/117640>\
**Category:** Rails\
**Created:** [October 18, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/newbie-question-persisting-an-object/117640 "2007-10-18T21:23:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dany\_Wu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3d9bf3/32.png) [@Dany\_Wu](https://www.ruby-forum.com/u/Dany_Wu)\
**Post date:** [October 18, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/newbie-question-persisting-an-object/117640/1 "2007-10-18T21:23:13Z")

</div>

Hi folks,

I’m new to RoR and getting stuck on something that should be quite  
simple. I’m just playing with a simple Blog concept, and working on  
the “create” view and action. Here are snippets the controller and  
view:

# ==================== def create @post = Post.new(params[:post]) if request.post? @post.save redirect\_to :action=\>‘index’ end end

===================  
\<% form\_for :post do |f| %\>

Title:  
 \<%= f.text\_field :title %\>

Content:  
 \<%= f.text\_field :content %\>

\<% end %\> \<%= submit\_tag %\> ===================

I have probably missed something simple and fundamental but can’t for  
the life of me see it. The create controller is not saving or  
redirecting to the index page. Please let me know if I need to post  
more code.

Any help or suggestions would be greatly appreciated.

Thanks,  
Dany.

---

<div class="post-metadata">

**Author:** ![Dany\_Wu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3d9bf3/32.png) [@Dany\_Wu](https://www.ruby-forum.com/u/Dany_Wu)\
**Post date:** [October 19, 2007, 3:10pm UTC](https://www.ruby-forum.com/t/newbie-question-persisting-an-object/117640/2 "2007-10-19T15:10:32Z")

</div>

Try putting the submit\_tag within the form\_for block:

\<% form\_for :post do |f| %\>

Title:  
 \<%= f.text\_field :title %\>

Content:  
 \<%= f.text\_field :content %\>

 \<%= submit\_tag %\> \<% end %\>

---

<div class="post-metadata">

**Author:** ![Dany\_Wu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3d9bf3/32.png) [@Dany\_Wu](https://www.ruby-forum.com/u/Dany_Wu)\
**Post date:** [October 19, 2007, 3:25pm UTC](https://www.ruby-forum.com/t/newbie-question-persisting-an-object/117640/3 "2007-10-19T15:25:11Z")

</div>

Maybe you need \<% form\_for(:post, :url =\> posts\_path) do |f| %\>

Check your development.log to make sure that your params are getting  
posted to the create method. Also look for errors there. I’m not  
sure but rails may not like the name post for your model.

---

<div class="post-metadata">

**Author:** ![Dany\_Wu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3d9bf3/32.png) [@Dany\_Wu](https://www.ruby-forum.com/u/Dany_Wu)\
**Post date:** [October 19, 2007, 7:59pm UTC](https://www.ruby-forum.com/t/newbie-question-persisting-an-object/117640/4 "2007-10-19T19:59:14Z")

</div>

D’oh! Thanks for pointing that out - at some stage, when I was  
stripping all the fancy presentation bits, the submit\_tag got pasted  
in the wrong place.

Thanks for pointing that out!

Cheers,  
Dany.
