Error de rutas de rieles. Ninguna ruta coincide con [POST] "/sessions/new"

Hello im doing tutorial from Rails Book and get into some troubles.

While im trying to log in with my username and password im getting the following error:

Error de enrutamiento

No route matches [POST] "/sessions/new" Try running rake routes for more information on available routes.

This is my route file config.

ZomfgShop::Application.routes.draw do
  get "admin/index"
  get "sessions/new"
  get "sessions/create"
  get "sessions/destroy"

  resources :users
  resources :orders
  resources :line_items
  resources :carts

  get "store/index"

  resources :products do
    get :who_bought, on: :member
  end

  resources :products

  root to: 'store#index', as: 'store'

  resources :line_items do
    #member do
    # post 'decrement'
    #end
    post 'decrement', on: :member
  end

  get 'admin' => 'admin#index'

  controller :sessions do
    get 'login' => :new
    post 'login' => :create
    delete 'logout' => :destroy
  end

preguntado el 28 de agosto de 12 a las 10:08

3 Respuestas

You have controller instead of resources for the :sessions routes.

  resources :sessions do
    get 'login' => :new
    post 'login' => :create
    delete 'logout' => :destroy
  end

Respondido 28 ago 12, 10:08

Intenta reemplazar

get "sessions/new"

get "sessions/create"

get "sessions/destroy"

con

resources :sessions

make sure you have a views/sessions/new.html.erb file (under views/devise/ if using devise)

and make sure you have this in sessions_controller.rb if you aren't using Devise

def new
end
def create
end
def destroy
end

Respondido 28 ago 12, 10:08

Thank you guys, changed my routes.rb file to this and my routing fine is working fine once again!

ZomfgShop::Application.routes.draw do
  get 'admin' => 'admin#index'

  controller :sessions do
    get 'login' => :new
    post 'login' => :create
    delete 'logout' => :destroy
  end
  scope '(:locale)' do
    resources :users
    resources :orders
    resources :line_items
    resources :carts
    get "store/index"
    resources :products do
      get :who_bought, on: :member
    end
  root to: 'store#index', as: 'store'
end

resources :line_items do
  #member do
  # post 'decrement'
  #end
  post 'decrement', on: :member
end

Respondido 28 ago 12, 14:08

If you put 4 spaces between each line of code, it will be nicely formatted and readable. - Elefante blanco

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.