I’m wanting to implement a way to preview a comment on my site. I’m
currently using ajax to save the comments now, so in order to do the
preview, I basically want to do the same thing without saving. That’s
no big deal.
Now, the place where I run into problems, is there is only one
“form_remote_tag” and two buttons. How to do I set things up for one to
call the “comments” action and for the other to call “comments_preview”
action from within one form?
Or am I thinking about this all wrong? Thanks!
A nice way of doing previews is to have them dynamically update, see
observe_field for this.
You can also use link_to_remote with a “:with” parameter and pass the
content of your form (Form.serialize):
<%= link_to_remote “Preview”, :update=>‘preview_panel’, :url=>{
:action=>‘preview’ }, :with=>“Form.serialize(‘form_id’)” %>
Max
prototype’s Form.serialize doesn’t handle submit buttons very well, in
that submit buttons, no matter how many get serialized, no matter if
they are named the same or not. so for example, you would get
name=Bob
action=save
action=preview
so what i would suggest, is you detach the buttons from the form,
perhaps making them button elements and create 2 javascript functions,
one to submit the comment for preview and one to submit the comment
for saving, and then attach to each button via onclick.
each function would then submit to a different controller/action to
handle accordingly.