I'm trying to create a simple form with two different submit buttons: one which will do a normal submit, and one which will do an ajax submit and render a partial. But I'm not sure how to do this because both go towards the same create action. I tried something like this:
/views/layouts/_form.html.erb:
<div id="theform">
<%= form_for(@user, :remote => true, :form_to_validate => 'user') do |f| %>
Name: <div id='name'><%= f.text_field :name %></div><br/>
Email: <div id='email'><%= f.text_field :email %></div><br/>
Phone Number: <div id='phone_number'><%= f.text_field :phone_number%></div><br/>
<%= f.submit "Normal Submit", name:'normal' %>
<%= f.submit "Ajax Submit" %>
<% end %>
</div>
app/controllers/user_controller.rb:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if params[:normal]
render :partial => "layouts/user"
end
end
EDIT: this may seem like an odd task but it was an assignment given to me to demonstrate I could do it both ways. I know how to do the AJAX submit and the normal submit separately but my confusion is with having two submits in the form! :)