abhir
abhir

Reputation: 1069

Rails - Routing Error for the POST method

Rails newbie here (trying to get these questions answered)

I'm using Ryan Bates' Rails Cast on Wicked Wizard Forms to create a multi-step form. I'm getting a "No route matches [POST] "/user_steps/gender" (where gender is a view under the user_steps controller).

Any ideas?

routes.rb:

Store::Application.routes.draw do

  resources :likes

  resources :categories


  resources :users
  resources :user_steps

  root to: 'static_pages#home'

user_steps controller:

class UserStepsController < ApplicationController
    include Wicked::Wizard
    steps :gender, :items, :brands, :final

    def show
        render_wizard
    end 

    def update
        @user.attributes = params[:user]
        render_wizard
    end
end

Upvotes: 2

Views: 1399

Answers (2)

techbrownbags
techbrownbags

Reputation: 626

I'm looking for rails wizards solutions and was going through "#346 Wizard Forms with Wicked" railscas when I ran into the same issue.

Adding a route, as @Klipfel suggests, is a good "rails" answer but not the correct approach for the wicked gem. If you add a route pointing to another controller method you are routing the request outside of the wicked framework.

I resolved this problem by specifying put for the http method. In the #346 Wizard Forms with Wicked railscast case it would look like this:

<%= form_for @user, url: wizard_path, method: :put do |f| %>

I'm not sure why it works in the railscast

Upvotes: 4

Peter Klipfel
Peter Klipfel

Reputation: 5178

When you define a new method, rails will default to a get request on that method. In order to make it a post method, try adding

match "user_steps/gender", to: "user_steps#gender", via: "post"

Check out this routes reference

Upvotes: 5

Related Questions