Newbie question: persisting an object

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.

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 %>

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.

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.