내 형태 :formtastic 액션에 맞춤 함수를 할당하는 방법은 무엇입니까?
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
campaign_controller.rb에
<%= 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 %>
기능 과 내가 이해할 수없는 유일한 것은, 함수를 호출하기 위해 행동을 작성하는 것입니다.
감사합니다, Cade, 꼭 맞게 작동합니다. 해결 됐어. –