0
resources :period_registrations do
member do
post :save_period
end
該點我的控制器操作:
def save_period
@period_registration = PeriodRegistration.new(params[:registration])
@period_registration.save
redirect_to root_path
end
和我有一個測試:
test "should get save_period" do
sign_in(FactoryGirl.create(:user))
assert_difference('Event.count') do
post :save_period, period_registration: FactoryGirl.attributes_for(:period_registration)
end
assert_not_nil assigns(:period_registration)
assert_response :success
end
運行時生成以下錯誤:
1) Error:
test_should_get_save_period(PeriodRegistrationsControllerTest):
ActionController::RoutingError: No route matches {:period_registration=>{}, :controller=>"period_registrations", :action=>"save_period"}
我看起來很奇怪的是:period_registration是空的。它應該是?我該如何解決這個問題?
所以我需要做的就是添加'後:save_period,:上=>:collection'正確嗎? –