SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: override the database.lyml
Hybrid View
-
Feb 19, 2006, 20:01 #1
- Join Date
- Feb 2006
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
override the database.lyml
hi...
i'm trying to override the database.yml. is it possible to insert a variable there, lets say the username and the password?
thanks!!!!
-
Feb 19, 2006, 22:14 #2
- Join Date
- Nov 2001
- Location
- Atlanta, GA, USA
- Posts
- 5,011
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
<%= %> tags seem to work, giving you access to whatever Ruby you wanted to throw into database.yml.
Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
-
Feb 20, 2006, 18:43 #3
- Join Date
- Feb 2006
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hi....
i tried smthg like this
username: <%= @session[:user].login %>
but i still got the error messg "rails could not connect to your database."
thanks 4 ur help
-
Feb 20, 2006, 20:01 #4
You won't be able to access anything in the normal Rails environment in your database.yml file - all you'll be able to use is normal Ruby.
-
Feb 20, 2006, 20:06 #5
- Join Date
- Feb 2006
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sorry, but i didn't get it.
do i hv to do it in the controller?
-
Feb 21, 2006, 04:40 #6
Originally Posted by masuk
Code:# in application.rb MyFancyModel.db_user = 'foo' MyFancyModel.db_pass = 'bar' class MyFancyModel < ActiveRecord::Base establish_connection( :adapter => 'mysql', :username => @@db_user, :password => @@db_pass ) end
You could then create models that use the above connection by extending MyFancyModel instead of AR::Base.
http://api.rubyonrails.com/classes/A...e.html#M000797
Bookmarks