没有路线匹配[POST]“/ manager”

时间:2015-09-28 11:29:26

标签: ruby-on-rails ruby routes

我在Rails中的第一个应用程序出错,并希望有人可以提供帮助,并告诉我一些线索如何处理。

错误:

  

没有路线匹配[POST]“/ manager”

当我提交此表格时:     

登录

SELECT count(*) FROM users WHERE created_at BETWEEN '2012-02-01 09:00' AND '2012-02-02 12:00' 

我的<div class="row"> <div class="span6 offset3"> <%= form_for(:session, url: manager_path) do |f| %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :password %> <%= f.password_field :password %> <%= f.submit "Sign in", class: "btn btn-large btn-primary" %> <% end %> </div> </div> 文件是:

route.rb

我的 Rails.application.routes.draw do resources :users resources :sessions, only: [:new, :create, :destroy] root 'static_pages#home' match '/manager', to: 'static_pages#manager', via: 'get' match '/signin', to: 'sessions#new', via: 'get' match '/signout', to: 'sessions#destroy', via: 'delete' end 是:

session_controller.rb

Ruby版本:2.1.5,Rails v.4.2.4

由于

2 个答案:

答案 0 :(得分:1)

更改为POST方法

Rails.application.routes.draw do
  resources :users
  resources :sessions, only: [:new, :create, :destroy]
  root 'static_pages#home'
  match '/manager', to: 'static_pages#manager',    via: 'post'
  match '/signin',  to: 'sessions#new',            via: 'get'
  match '/signout', to: 'sessions#destroy',        via: 'delete'
end

manager方法添加到StaticPagesController

class StaticPagesController < ApplicationController

  def manager
     # Create logic goes here 
  end

end

答案 1 :(得分:0)

 Rails.application.routes.draw do
  resources :users
  resources :sessions, only: [:new, :create, :destroy]
  root 'static_pages#home'
  match '/manager', to: 'static_pages#manager',    via: 'get'
  match '/manager', to: 'sessions#create',         via: 'post'
  match '/signin',  to: 'sessions#new',            via: 'get'
  match '/signout', to: 'sessions#destroy',        via: 'delete'
end

现在方法将可用于/ manager with post,它将转到会话控制器创建方法

检查此路线

match '/manager', to: 'sessions#create', via: 'post'

这种方法说。路由名称为/managers控制器为sessions sessions#createcreate为来自sessions#create的控制器会话方法。