设计不正确阅读用户模型?

时间:2014-05-02 02:01:56

标签: ruby-on-rails-3 devise rubymine warden

我让我的应用程序正常运行大约一年了,但我改变了一些我想的东西,现在我得到了奇怪的Devise错误,如下所示。 *请注意rails控制台工作正常,activerecord模型(包括用户)可以正常访问,我可以得到User.email没问题。但是我想这些观点并不奏效。它似乎在User.email上出现了一个no方法错误,这确实非常奇怪。我能想到的唯一可能导致这些问题的是最近将Ruby矿山升级到最新版本6.3。也许宝石以某种不相容的方式改变了?

Started GET "/" for 127.0.0.1 at 2014-05-01 18:40:12 -0700
Processing by WelcomeController#main as HTML
Completed 401 Unauthorized in 1ms


Started GET "/users/sign_in" for 127.0.0.1 at 2014-05-01 18:40:12 -0700
Processing by Devise::SessionsController#new as HTML
  Rendered devise/sessions/new.html.erb within layouts/application (6.0ms)
Completed 500 Internal Server Error in 18ms

ActionView::Template::Error (undefined method `email' for #<User >):
    3: <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
    4:     <div><%= f.label :email %>
    5:       <br/>
    6:       <%= f.email_field :email %></div>
    7: 
    8:     <div><%= f.label :password %>
    9:       <br/>
  app/views/devise/sessions/new.html.erb:6:in `block in _app_views_devise_sessions_new_html_erb__882742671_47657856'
  app/views/devise/sessions/new.html.erb:3:in `_app_views_devise_sessions_new_html_erb__882742671_47657856'


  Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
  Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
  Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (16.0ms)

注意我在视图中添加了一行:     &lt;%u = User.first%&gt; 它检索第一个用户没问题。所以我不是为什么Devise感到困惑。出于某种原因,我怀疑Warden可能有问题,但那里的代码非常不透明(至少对我而言)

宝石如下。

捆绑包含的宝石:

  * actionmailer (3.2.11)
  * actionpack (3.2.11)
  * activemodel (3.2.11)
  * activerecord (3.2.11)
  * activerecord-sqlserver-adapter (3.2.12)
  * activeresource (3.2.11)
  * activesupport (3.2.11)
  * arel (3.0.3)
  * bcrypt-ruby (3.0.1)
  * best_in_place (2.1.0)
  * builder (3.0.4)
  * bundler (1.5.3)
  * capistrano (2.15.5)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.7.0)
  * debugger-ruby_core_source (1.3.2)
  * devise (2.1.2)
  * dynamic_form (1.1.4)
  * erubis (2.7.0)
  * excon (0.31.0)
  * execjs (2.0.2)
  * fog (1.20.0)
  * formatador (0.2.4)
  * formtastic (2.2.1)
  * highline (1.6.21)
  * hike (1.2.3)
  * i18n (0.6.9)
  * journey (1.0.4)
  * jquery-rails (3.1.0)
  * jquery-ui-rails (4.1.2)
  * json (1.8.1)
  * mail (2.4.4)
  * mime-types (1.25.1)
  * mini_portile (0.5.2)
  * monetize (0.1.4)
  * money (6.0.1)
  * multi_json (1.9.3)
  * net-scp (1.1.2)
  * net-sftp (2.1.2)
  * net-ssh (2.7.0)
  * net-ssh-gateway (1.2.0)
  * nokogiri (1.6.1)
  * orm_adapter (0.5.0)
  * polyglot (0.3.4)
  * rack (1.4.5)
  * rack-cache (1.2)
  * rack-ssl (1.3.4)
  * rack-test (0.6.2)
  * rails (3.2.11)
  * rails3-jquery-autocomplete (1.0.12)
  * railties (3.2.11)
  * rake (10.3.1)
  * rdoc (3.12.2)
  * ruby-debug-base19x (0.11.30.pre15)
  * ruby-debug-ide (0.4.22)
  * ruby-odbc (0.99995)
  * sass (3.3.2)
  * sass-rails (3.2.6)
  * sprockets (2.2.2)
  * sql_server (0.1.1)
  * thor (0.19.1)
  * tilt (1.4.1)
  * treetop (1.4.15)
  * tzinfo (0.3.39)
  * uglifier (2.5.0)
  * warden (1.2.3)
  * win32ole-pp (1.2.0)

1 个答案:

答案 0 :(得分:0)

好吧,事实证明Devise似乎不喜欢在database.yml中的erb。

我破坏了我的应用程序的更改是替换它:

development:
  adapter: sqlserver
  host: my_server.xxx.rds.amazonaws.com
  port: 1433
  database: MyDatabase 
  username: sa  
  password: the_password   

用这个:

development:
  adapter: sqlserver
  host: my_server.xxx.rds.amazonaws.com
  port: 1433
  database: MyDatabase 
  username: <%= CredentialsManager.get_db_user %>
  password: <%= CredentialsManager.get_db_pass %> 

虽然不需要通过设计进行身份验证的页面使用新的database.yml访问数据库没有问题,但是当使用Devise时,它看起来引用的用户模型根本没有属性。 (由| f |表示的用户对象具有类#的@object属性,@ object的属性hash为nil。因此当使用database.yml访问db时,内部设计会发生奇怪的事情。不太确定为什么这是发生了,但那是另一个线索......