Hi Patrick,

I would prefer to have the preview on a separate page, so that if the
object is validated, the user is sent to the preview page, and it it
is not, the user is sent back to the form by using "render :action =>
'new'", which will display the form + errors.  On the preview page,
there would be a choice to continue and agree to terms and conditions
or to edit the post.  The easiest way I see to do this is to actually
create the post, and then if the user does not press continue or agree
to the terms and conditions, delete the posting from the database.
However, this would require a lot of unnecessary calls to the database
(if there is a way to store and pass a temporary object), and would
also cause posting id numbers to not be consecutive (say, if a user
does not commit to the post.)  I'm tempted to go with this approach
because it is the easiest, however the inefficiency of this approach
scares me.

Cheri

On Jul 15, 10:55 am, Patrick Crowley <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to