I have a form with two submit buttons: "Save" and "Preview". In my
controller for this form, I do different things based on
params[:commit]. But somehow the params[:commit] always evals "Save",
even when I click Preview button. Why? any idea will be appreciated.

This is my view:
<% remote_form_for(@post) do |f| %>
  <%= f.error_messages %>
  <%= f.hidden_field :id %>
  <p>
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </p>
  <p>
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.submit "Save" %>&nbsp;&nbsp;
    <%= f.submit "Publish" %>
  </p>
<% end %>

This is my controller:
  def create
    @post = Post.new(params[:post])
    @post.id = params[:post][:id]
    begin
      if params[:commit] == 'Publish'
        @post.published = true
        @post.save
        flash[:notice] = 'Post was successfully published.'
        redirect_to posts_path
      else
        @post.published = false
        @post.save
        flash[:notice] = 'Post was successfully saved.'
      end
    rescue => ex
      flash[:notice] = ex.message
      render :action => :new
    end
  end
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to