0

I am trying to implement a "Preview" feature before creating an object for a product. I followed Ryan Bates railscast on doing so, in which he does so by passing a parameter :name with the submit button.

<%= submit_tag 'Preview', :name => 'preview_button' %>

However, it's not working in my case, don't know why, may be because I'm using rails 3, I can't tell, but I do not see any changes when I add :name => 'preview_button' with the submit button. Can anyone suggest me a solution?

1
  • Please include your controller code that you are using as well. Commented Mar 27, 2011 at 22:48

2 Answers 2

3

Adding Paulo's answer, it might be better to route to different actions based on commit param.

We solved using advanced constraints in rails.

The idea is to have the same path (and hence the same named route & action) but with constraints routing to different actions.

resources :plan do
  post :save, constraints: CommitParamRouting.new("Propose"), action: :propose
  post :save, constraints: CommitParamRouting.new("Finalize"), action: :finalize
end

CommitParamRouting is a simple class that has a method matches? which returns true if the commit param matches the given instance attr. value.

This available as a gem commit_param_matching.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to add two submit buttons with different names

<%= submit_tag 'Submit', :name => 'submit_button' %>
<%= submit_tag 'Preview', :name => 'preview_button' %>

then in your controller you need to check the parameters:

if params[:commit] == "Submit"
# do great stuff
end
if params[:preview] == "Preview"
# preview great stuff
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.