私のフォーム:
<%= semantic_form_for(@campaign) do |f| %>
...
<%= f.actions do %>
<%= f.action :submit, label: "Save"%>
<%= f.action :submit, label: "Save & New" %>
<%= f.action :cancel, label: "Cancel"%>
<% end %>
<% end %>
campaign_controller.rbの関数:
def save_and_new
print 'SAVE_AND_NEW'
@campaign = Campaign.find(params[:id])
respond_to do |format|
if @campaign.update_attributes(params[:campaign])
format.html { redirect_to new_campaign_path, notice: 'Campaign was successfully usaved.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @campaign.errors, status: :unprocessable_entity }
end
end
end
Routes.rb:
resources :campaigns do
member do
post 'save_and_new'
end
end
機能に応じたルート:
save_and_new_campaign POST /campaigns/:id/save_and_new(.:format) campaigns#save_and_new
そして、私が理解していない唯一のことは、関数を呼び出すために実際に何を書くかということです。