在Rails升级后丢失视图中的Rails.application.routes.url_helpers访问权限

时间:2013-05-20 15:31:56

标签: ruby-on-rails ruby-on-rails-3 routes upgrade

我正在尝试将应用程序从Rails 2.3升级到3.2。我目前遇到的问题是视图中缺少Rails.application.routes.url_helpers。

因此,例如,我的 routes.rb 文件包含(部分):

MyApp::Application.routes.draw do
  resources :users
end

并运行 rake路径向我显示我有以下内容:

users  GET   /users(.:format)  users#index
       POST  /users(.:format)  users#create

但是,当我尝试在HAML视图中使用 users_path 时,例如在以下示例中:

- if logged_in?
  %ul.nav
  - if user_can?(:see_users?)
    %li.users= link_to "Users", users_path

然后我收到以下错误:

undefined local variable or method `users_path' for #<#<Class:0x000001045eda80>:0x000001030f6bb8>

但是,如果 ApplicationController 更改为包含:

include Rails.application.routes.url_helpers

然后一切都好。问题是,为什么升级后视图中的助手不会自动提供?


更新:根据以下评论中的要求,Gemfile为:

source 'http://rubygems.org'
source 'http://gems.github.com'

gem 'rails', '3.2.13'
gem 'rake', '10.0.4'
gem 'haml', '3.1.4'
gem 'responders', '0.9.3'
gem 'inherited_resources', '1.4.0'
gem 'formtastic', '2.2.1'
# Note: validation_reflection coming from git for now as it has the fix for
# https://github.com/redinger/validation_reflection/pull/13 in it, while the
# current official 1.0.0 release does not have the fix. Can be changed back
# to a version number if 1.0.1 is released.
gem 'validation_reflection', :git => 'git://github.com/redinger/validation_reflection.git'
gem 'treetop'
gem 'authlogic', '3.1.2'
gem 'param_protected', '2.0.0'
gem 'chronic', '0.2.3'
gem 'amon', '0.12.0'
gem 'aws-sdk', '1.9.5'
gem 'paperclip', '3.4.1'
gem 'json', '~> 1.4.3'
gem 'airbrake', '~> 3.0.5'
gem 'bluecloth', '>= 2.0.0'
gem 'less'
gem 'therubyracer'
gem 'mysql'
gem 'rdoc'
gem 'thin', '1.3.1'
gem 'delayed_job', '3.0.5'
gem 'delayed_job_active_record'
gem 'will_paginate', '3.0.4'
gem 'newrelic_rpm'
gem 'tiny_mce'
gem 'geocoder'
gem 'safe_attributes'

group :development do
  gem 'capistrano', "~> 2.13.5"
  gem 'capistrano-ext'
  gem 'rvm-capistrano'
  gem 'ci_reporter', '1.6.5'
end

group :development, :test, :cucumber do
  gem 'pry'
  gem 'rspec', '1.3.2'
  gem 'rspec-rails', '~> 1.3.0', :require => 'spec'
  gem 'email_spec', '0.6.5'
  gem 'seed-fu'
end

group :test do
  gem 'mocha', '0.9.8'
  gem 'machinist', '1.0.6'
  gem 'faker', '0.3.1'
  gem 'timecop', '0.3.5'
  gem 'fakeweb', '1.3.0'
  gem 'shoulda'
  gem 'uuid', "~> 2.3.7"                    # MIT
end

group :cucumber do
  gem "cucumber", "~> 1.1.0"
  gem "cucumber-rails", "~> 0.3.2"
  gem "capybara", "~> 1.1.1"
  gem 'database_cleaner', "~> 0.5.0"
  gem 'launchy'
  gem 'uuid', "~> 2.3.7"                    # MIT
end

0 个答案:

没有答案