Ruby on Rails - 未定义的局部变量或方法"signin_path"



我收到这个错误,但它对我来说没有意义

这里的测试:

describe "edit" do
        let(:user) { FactoryGirl.create(:user) }
        before(:each) do
            sign_in user
            visit edit_user_path(user)
        end
        it{ should have_content('Profile Settings')}
        it{ should have_title(full_title('Settings'))}
        describe "invalid information" do
            before { click_button "Save changes" }
            it { should have_content('error') }
        end
        describe "valid information" do
            let(:new_name) { "Test name" }
            let(:new_email) { "test@email.com" }
            before do
                fill_in "Name", with: new_name
                fill_in "Email", with: new_email
                fill_in "Password", with: user.password
                fill_in "Password Confirmation", with: user.password
                click_button "Save changes"
            end
            it { should_not have_content('error')}
            it { should have_title(new_name)}
        end
    end

我的路线.rb:

Rails.application.routes.draw do
  devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)
  resources :users do
    member do
        get :following, :followers
    end
  end
    resources :podcasts,            only: [:index, :new, :create, :destroy]
    resources :sessions,            only: [:new, :create, :destroy]
    resources :relationships,       only: [:create, :destroy]
    root to: 'static_pages#home'
    match '/about',  to: 'static_pages#about', via: 'get'
    match '/contact',  to: 'static_pages#contact', via: 'get'
    match '/community',  to: 'users#community',   via: 'get'
    match '/signup',  to: 'users#new',            via: 'get'
    match '/signin',  to: 'sessions#new',         via: 'get'
    match '/signout', to: 'sessions#destroy',     via: 'delete' 
end

当我运行rake路由时:

                signup GET        /signup(.:format)                         users#new
                signin GET        /signin(.:format)                         sessions#new

我的gemfile:

source 'https://rubygems.org'
ruby '2.2.1'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.8'
gem 'bootstrap-sass'
gem 'sprockets', '2.11.0'
gem 'bcrypt-ruby', '3.1.2'
gem 'faker', '1.1.2'
gem 'will_paginate', '3.0.4'
gem 'bootstrap-will_paginate', '0.0.9'
#gem "minitest", "~> 4.0"
gem 'devise'
gem 'activeadmin', github: 'activeadmin/activeadmin', branch: :master
gem 'rmagick', '2.13.2', :git=>'http://github.com/rmagick/rmagick.git'
gem 'carrierwave'
group :development, :test do
  #gem 'sqlite3', '1.3.8'
  gem 'sqlite3'
  gem 'rspec-rails'
  # The following optional lines are part of the advanced setup.
  gem 'guard-rspec'
  gem 'spork-rails', '4.0.0'
  gem 'guard-spork', '2.1.0'
  gem 'childprocess', '0.3.6'
  end
group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.2.0'
  gem 'factory_girl_rails', '4.2.0'
  gem 'cucumber-rails', '1.3.0', :require => false
  gem 'database_cleaner', github: 'bmabey/database_cleaner'
  # Uncomment this line on OS X.
  #gem 'growl', '1.0.3'
  # Uncomment these lines on Linux.
   gem 'libnotify', '0.8.0'
  # Uncomment these lines on Windows.
  # gem 'rb-notifu', '0.0.4'
  # gem 'win32console', '1.3.2'
  # gem 'wdm', '0.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
  gem 'sdoc', '0.3.20', require: false
end
group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

我确实发现了两个类似的问题,但没有太大帮助(或者我理解错了(

类似的问题:Rails教程第8章-未定义的局部变量或方法'signin_path';

RailsTutorial Ch 9:signin_path是未定义的局部变量?电子邮件已被接收?

谢谢。

我怀疑你是否有Sessions控制器,但你已经安装了Devise,所以请注意我的路由中的原生设备会产生以下行(看看结尾(

new_user_session GET        /users/sign_in(.:format)    devise/sessions#new
destroy_user_session DELETE /users/sign_out(.:format)   devise/sessions#destroy

所以我认为您必须引用的不是session#new,而是device/sessions#new。在您的路线中尝试以下操作。rb:

更换行

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

带有

get '/signin',  to: 'device/sessions#new'
delete '/signout', to: 'device/sessions#destroy'

实际上prolbem是我放在我的规范文件中的任何路径,都没有被重新配置

这些问题帮助我解决了这个问题:

Rspec和命名路线

这个答案就是解决方案:

如果在rsspec_helper.rb:中放入以下内容,则命名路由应该有效

RSpec.configure do |config|
  config.include Rails.application.routes.url_helpers
  ...
end

你就是这样安排的吗?


有点令人困惑的是,我在学习sample_app_rails教程,但这一行没有出现。。。

不管怎样,谢谢大家的帮助。

相关内容

  • 没有找到相关文章

最新更新