1

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"

1
  • are you sure the request you are making is a post request. By your route definition, get requests to survey/step_3 will be rejected. Commented May 15, 2011 at 2:59

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.