I would recommend using the standard save method here.
If your controller is RESTFUL, it might look like this:
class PostsController < ApplicationController
def new
@post = Post.new
end
def create
@post = Post.new(params[:post])
if @post.save
flash[:notice] = 'Post was successfully created.'
redirect_to(@post)
else
render :action => "new"
end
end
end
end
Sometimes, I like to merge these two actions into one:
class PostsController < ApplicationController
def new
@post = Post.new(params[:post])
if request.post?
if @post.save
flash[:notice] = 'Post was successfully created.'
redirect_to(@post)
end
end
end
end
....
If you need to have a preview right there in the form, you could
include a partial that contains the markup needed to display a post,
and pass it your @post object.
So, below your form, you would add this:
<% if request.post && @post %>
<%= :partial => "preview", :object => @post %>
<% end %>
Now, depending on your validation rules, displaying something that
isn't valid could be kinda hairy, but you could find ways to work
around that.
-- Patrick
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---