This problem was resolved by changing the db username from 'asadmin_app' to just 'asadmin' No idea why devise doesn't like db usernames with underscores, but it seems like some kind of bug to me. Rails itsef, and SQL Server (the backing DB) have no problem with _ in a username, but soemthing goes screwy when devise and warden get involve.d
Using erb in database.yml breaks Devise
-
14-07-2023 - |
Вопрос
I updated by database.yml to get credentials out of the file for security purposes, and replaced them with a call via erb to an object that reads the info from a file.
This seems to work fine when authentication isn't involved, but when devise generated views seem to break.
This version of database.yml that breaks it:
development:
adapter: sqlserver
host: my_server.xxx.rds.amazonaws.com
port: 1433
database: MyDatabase
username: <%= CredentialsManager.get_db_user %>
password: <%= CredentialsManager.get_db_pass %>
But the console, and pages that don't call authentication have no problem accessing model attributes.
However views like devise/sessions/new.html.erb, seem to be looking in the wrong place for the User model. Form breaks with errors like these, where the user model appears to have no 'email' attribute:
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)
Examining the |f| parameter in the debugger shows that it has an @object attribute of class User, but the @attributes hash of @object is an empty hash, and @column_names is an empty array.
Does anyone have an idea how to fix this? I need to get credentials out of database.yml, and this is the way I'd like to do it.
Environment Rails 3.2.11 Devise 2.1.2 Warden 1.2.1
Решение