#38
May 30
Multibutton Form
If you have a form with multiple buttons, you can detect which button was clicked by checking the passed parameters. Learn how in this episode.
<!-- projects/new.rhtml --> <% if params[:preview_button] %> <%= textilize @project.description %> <% end %> ... <%= submit_tag 'Create' %> <%= submit_tag 'Preview', :name => 'preview_button' %>
# projects_controller.rb def create @project = Project.new(params[:project]) if params[:preview_button] || !@project.save render :action => 'new' else flash[:notice] = "Successfully created project." redirect_to project_path(@project) end end




很好,
我很喜欢看你的例子!!
This is too funny. I was halfway through a post on railsforum asking how to do exactly this when my RSS alerted me to a new Railscast. Your timing could not be better!
d:)
I'm agree with the first comentary ;)
Clever stuff!
well done!
One way round the AJAX form problem is to have one submit button, and use a "preview" checkbox.
Another great railscast! please keep them coming!
how to use submit_to_remote?
will you give me a example,
i test it 10 hours ,but ,i cannt .
hehe!
I found the multibutton form can be work only for form_for, but not for form_remote_for