ruby-on-rails – 来自Ruby on Rails的无路由错误教程Michael Hartl第8章

我正在研究Michael Hartl的Ruby on rails.我被困在8.1.4部分,它正在使用Rails 3.2.3和Ruby 1.9.3-p125实现登录页面.

我已经创建了一个会话控制器,我希望我的会话控制器创建动作映射到此路由/会话,但始终是路由错误.有线索吗?以下是我的相关文件:

的routes.rb

SampleApp::Application.routes.draw do

  resources :users
  resources :sessions, only: [:new, :create, :destroy]

  root to: 'static_pages#home'

  match '/signup',  to: 'users#new'
  match '/signin',  to: 'sessions#new'
  match '/signout', to: 'sessions#destroy', via: :delete

  match '/help',    to: 'static_pages#help'
  match '/about',   to: 'static_pages#about'
  match '/contact', to: 'static_pages#contact' 
end

和我的佣金路线:

      users GET    /users(.:format)          users#index
            POST   /users(.:format)          users#create
   new_user GET    /users/new(.:format)      users#new
  edit_user GET    /users/:id/edit(.:format) users#edit
       user GET    /users/:id(.:format)      users#show
            PUT    /users/:id(.:format)      users#update
            DELETE /users/:id(.:format)      users#destroy
   sessions POST   /sessions(.:format)       sessions#create
new_session GET    /sessions/new(.:format)   sessions#new
    session DELETE /sessions/:id(.:format)   sessions#destroy
       root        /                         static_pages#home
     signup        /signup(.:format)         users#new
     signin        /signin(.:format)         sessions#new
    signout DELETE /signout(.:format)        sessions#destroy
       help        /help(.:format)           static_pages#help
      about        /about(.:format)          static_pages#about
    contact        /contact(.:format)        static_pages#contact

我的app / views / sessions / new.html.erb:

  <%= provide(:title, 'Sign in') %>
  <h1>Sign in</h1>

 <div class="row">
 <div class="span6 offset3">
   <%= form_for(:session, url: sessions_path) do |f| %>

     <%= f.label :email %>
     <%= f.text_field :email %>

     <%= f.label :password %>
     <%= f.password_field :password %>

     <%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
   <% end %>

   <p>New user? <%= link_to "Sign up now!", signup_path %></p>
 </div>

我的会话控制器:

class SessionsController < ApplicationController
  def new
  end

  def create
    render 'new'
  end

  def destroy
  end
end

figure 8.5中,图片显示登录的URL是http://localhost:3000/sessions.当我导航到该页面时,

我总是得到一个

Routing Error
    No route matches [GET] "/sessions"

解决了

图8.5显示了点击创建按钮后的页面,并且网址从/ sessions / new或/ signin更改为/ sessions,所以我的上述文件没有任何问题.

最佳答案
我认为这是一个错字.您必须按照路线中的指示naviagte到http:// localhost:3000 / sessions / new.

转载注明原文:ruby-on-rails – 来自Ruby on Rails的无路由错误教程Michael Hartl第8章 - 代码日志