I have a nested route:
resources :period_registrations do
member do
post :save_period
end
that points to my controller action:
def save_period
@period_registration = PeriodRegistration.new(params[:registration])
@period_registration.save
redirect_to root_path
end
and I have a test:
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
That when run generates the following error:
1) Error:
test_should_get_save_period(PeriodRegistrationsControllerTest):
ActionController::RoutingError: No route matches {:period_registration=>{}, :controller=>"period_registrations", :action=>"save_period"}
What looks odd to me is that :period_registration is empty. Should it be? How can I solve this?
postshould be defined forcollection, i.e. you need to change your routing:instead of
memberblock. As an example, rails build-increate(generated by theresources) method also binded to a collection.Additional notes:
PeriodRegistration.new(params[:registration]), but should bePeriodRegistration.new(params[:period_registration]).should get save_period=>should post save_period