gpt4 book ai didi

ruby-on-rails - rails : Undefined method 'to_sym'

转载 作者:数据小太阳 更新时间:2023-10-29 07:27:46 25 4
gpt4 key购买 nike

我在部署的 Rails 2.3.5 应用程序中遇到以下错误:

NoMethodError (undefined method `to_sym' for nil:NilClass):

我使用 Sqlite 的应用程序的本地测试安装没有出现错误,但我部署的运行 Mysql 的应用程序出现了错误。两者之间唯一的区别是我在我的本地机器上运行 Ruby 1.8.7 而在我的部署服务器上运行 1.8.6。

我已经包含了 User.rb 中的代码和下面的错误日志。我按照声明式授权和嵌入式授权 Railscasts 进行设置。


编辑:这是 application_controller 的代码,我在其中使用 before_filter 设置了 current_user:

class ApplicationController < ActionController::Base
helper :all
helper_method :current_user_session, :current_user
before_filter :set_current_user

protected

def set_current_user
Authorization.current_user = current_user
end

def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end

def current_user
@current_user = current_user_session && current_user_session.record
end
end

--

用户.rb:

class User < ActiveRecord::Base
acts_as_authentic

has_many :products
has_many :transactions

ROLES = %w[admin dmstaff staff faculty]

def role_symbols
[role.to_sym]
end

end

错误日志:

NoMethodError (undefined method `to_sym' for nil:NilClass):
app/models/user.rb:10:in `role_symbols'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization 0.4/lib/declarative_authorization/authorization.rb:242:in `roles_for'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization-0.4/lib/declarative_authorization/authorization.rb:296:in `user_roles_privleges_from_options'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization-0.4/lib/declarative_authorization/authorization.rb:161:in `permit!'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization-0.4/lib/declarative_authorization/in_controller.rb:580:in `permit!'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization-0.4/lib/declarative_authorization/in_controller.rb:109:in `filter_access_filter'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization-0.4/lib/declarative_authorization/in_controller.rb:109:in `each'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization-0.4/lib/declarative_authorization/in_controller.rb:109:in `all?'
/usr/lib/ruby/gems/1.8/gems/declarative_authorization-0.4/lib/declarative_authorization/in_controller.rb:109:in `filter_access_filter'
passenger (2.2.5) lib/phusion_passenger/rack/request_handler.rb:95:in `process_request'
passenger (2.2.5) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
passenger (2.2.5) lib/phusion_passenger/railz/application_spawner.rb:378:in `start_request_handler'
passenger (2.2.5) lib/phusion_passenger/railz/application_spawner.rb:336:in `handle_spawn_application'
passenger (2.2.5) lib/phusion_passenger/utils.rb:183:in `safe_fork'
passenger (2.2.5) lib/phusion_passenger/railz/application_spawner.rb:334:in `handle_spawn_application'
passenger (2.2.5) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
passenger (2.2.5) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
passenger (2.2.5) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
passenger (2.2.5) lib/phusion_passenger/abstract_server.rb:163:in `start'
passenger (2.2.5) lib/phusion_passenger/railz/application_spawner.rb:213:in `start'
passenger (2.2.5) lib/phusion_passenger/spawn_manager.rb:262:in `spawn_rails_application'
passenger (2.2.5) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
passenger (2.2.5) lib/phusion_passenger/spawn_manager.rb:256:in `spawn_rails_application'
passenger (2.2.5) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
passenger (2.2.5) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (2.2.5) lib/phusion_passenger/spawn_manager.rb:255:in `spawn_rails_application'
passenger (2.2.5) lib/phusion_passenger/spawn_manager.rb:154:in `spawn_application'
passenger (2.2.5) lib/phusion_passenger/spawn_manager.rb:287:in `handle_spawn_application'
passenger (2.2.5) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
passenger (2.2.5) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
passenger (2.2.5) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'

Rendering /var/data/app/current/public/500.html (500 Internal Server Error)

最佳答案

  def role_symbols
[role.to_sym]
end

-> 角色Nil。您是否在某处定义了role

关于ruby-on-rails - rails : Undefined method 'to_sym' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2267163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com