4

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

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

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

并且运行rake routes告诉我我有以下内容:

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
4

0 回答 0