我的表格:
<%= 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
路线.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
唯一我不明白的是,在调用函数时要写什么。