ruby on rails - How can I get my stand alone ActiveRecord::Base tool to connect to my production database? -


this script created add users onto production database.

puts "name of user" name = gets.chomp  puts "login of user" login = gets.chomp 

etc. etc.....

what want connect production database can manage new users without having type lot of fields multiple times.

at top of file i've tried few ways connect database no avail....

attempt 1:

require 'config/environment.rb' 

this connects me development database

attempt 2:

require 'active_record' activerecord::base.establish_connection(:production)  `establish_connection': production database not configured (activerecord::adapternotspecified) 

attempt 3:

require 'active_record' activerecord::base.establish_connection(:adapter => 'postgresql', :host => 'company_host')  load_missing_constant': uninitialized constant rails (nameerror) 

attempt 4:

  require 'active_record' activerecord::base.establish_connection(:adapter => 'postgresql', :host => 'company_host', :database => '/var/local/config/database.yml')    load_missing_constant': uninitialized constant rails (nameerror) 

attempt 5:

activerecord::base.establish_connection(:adapter => 'postgresql', :host => 'host.company.com',                                     :database => 'production', :user => 'user', :password => 'password') 

my database.yml file entry production database looks this.

production:   db_host: host.company.com   db_name: production   db_pass: password   db_user: user 

i've tried other combinations found here api guide no avail. running rails 2.3.8. , ruby 2.0. appreciated.

i create special rake task.

  1. assuming i'd want separate namespace manual , name of task create_user:

    namespace manual   task :create_user => :environment     puts "name of user"     name = gets.chomp      puts "login of user"     login = gets.chomp   end 
  2. run env=production rake manual:create_user

you pass parameters rake task, if helps.

not sure if looking for, maybe turns out faster alternative you're trying achieve.

go ahead , comment on answer if doesn't :)


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -