您好我正在从Rails Book做教程并遇到一些麻烦。
我尝试使用我的用户名和密码登录时遇到以下错误:
路由错误
没有路线匹配[POST]“/ sessions / new” 尝试运行rake路线以获取有关可用路线的更多信息。
这是我的路线文件配置。
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
答案 0 :(得分:0)
对于:sessions路由,您有控制器而不是资源。
resources :sessions do
get 'login' => :new
post 'login' => :create
delete 'logout' => :destroy
end
答案 1 :(得分:0)
尝试替换
get "sessions/new"
get "sessions/create"
get "sessions/destroy"
与
resources :sessions
确保您有一个views / sessions / new.html.erb文件(在views / devise /下使用设计)
如果你没有使用Devise
,请确保你在sessions_controller.rb中有这个def new
end
def create
end
def destroy
end
答案 2 :(得分:0)
谢谢大家,将我的routes.rb文件更改为此,我的路由再次正常工作!
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