Reputation: 4716
In routes.rb I have:
get "survey/show" => "survey#show"
post "survey/step_2" => "survey#step_2"
post "survey/step_3" => "survey#step_3"
And in step_2.html.erb I have:
<%= form_for @result, :url => { :controller => 'survey', :action => 'step_3' } do |f| %>
And in survey_controller.rb I have:
def step_2
@result = Result.new(params[:result])
if @result.save
session[:result_id] = @result.id
render :action => "step_2"
else
render :action => "show"
end
end
def step_3
@result = Result.find(session[:result_id])
if @result.update_attributes(params[:result])
render :action => "step_3"
else
render :action => "step_2"
end
end
And when I submit the form on step_2 I get the following error:
No route matches "/survey/step_3"
Upvotes: 1
Views: 1953
Reputation: 8290
I believe Rails form_for method may be making that a PUT request, since the @result object has an id. I believe you should change your form_for line to:
<%= form_for @result, :url => { :controller => 'survey', :action => 'step_3' }, :html => { :method => :post} do |f| %>
or change the route type to put
in routes.rb
Upvotes: 3
Reputation: 6882
You have to use match.
match 'survey/step_3' => 'survey#step_3', :via => 'post'
I might be wrong about the :via, but it's something like that.
Upvotes: 0