我有一个嵌套路线:
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 是空的。应该是吗?我该如何解决这个问题?