Ruby on Rails connection SQL Oracle problems - sql

I'm trying to setup SQL Oracle and use active records to migrate db with ruby on rails.
I installed sqldeveloper and created a new connection. Here the first error:
I/O error: The Network Adapeter could not establish the connection
Then I installed instantclient basic, sdk, sqlplus and then two gems:
gem 'ruby-oci8'
gem 'activerecord-oracle_enhanced-adapter'
but I got this error:
LoadError: Could not load 'active_record/connection_adapters/oracle_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
this is my database.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
development:
adapter: oracle
database: development
username: nick
password:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: oracle
database: test
username: nick
password:
production:
adapter: oracle
database: production
username: nick
password:
I wasn't able to find a solution, what can I do?

Update adapter entries as follows:
adapter: oracle
to
adapter: oracle_enhanced

Related

Rails 5 Server Issues (Windows 10)

Newbie to Ruby on Rails here, I just did a fresh install of Ruby & Rails on Windows 10 (Bash on Ubuntu shell). I seems to having issues on starting the Rails server. Already checked the other threads on the issue, but everyone else is using OSX. :( Hope someone can help!
When running rails s,
root#TEAMROCKETHQ:~/newapp# rails s
/root/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/railties-5.0.2/lib/rails/app_loader.rb:40: warning: Insecure world writable dir /root/.rbenv/versions in PATH, mode 040777
=> Booting Puma
=> Rails 5.0.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.0 (ruby 2.4.0-p0), codename: Sassy Salamander
* Min threads: 5, max threads: 5
Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
For the first line issue, I tried:
sudo chmod 775 /usr/local
it seems it didn't do anything. Maybe I'm reading the error wrong, but I don't know... When I go to localhost:3000, it returns this error:
=> Booting Puma
=> Rails 5.0.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.0 (ruby 2.4.0-p0), codename: Sassy Salamander
* Min threads: 5, max threads: 5
Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
2017-03-09 23:17:26 -0600: Read error: #<Errno::EINVAL: Invalid argument - getsockopt(2)>
/root/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.0/lib/puma/server.rb:124:in `getsockopt'
/root/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.0/lib/puma/server.rb:124:in `closed_socket?'
/root/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.0/lib/puma/server.rb:563:in `handle_request'
/root/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.0/lib/puma/server.rb:425:in `process_client'
/root/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.0/lib/puma/server.rb:289:in `block in run'
/root/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/puma-3.8.0/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Webpage:
The localhost page isn't working
localhost is currently unable to handle this request.
HTTP ERROR 500
It is because puma 3.8.0.
Put gem 'puma', '3.7.1' in your gem file, and bundle install again.
And gem uninstall puma at version 3.8.0, wait until there is a fix.

What configuration for Rails 3.2.22.2 + Puma + Heroku?

I've read Richard Schneeman's article, and a bunch of other ones. ;-)
I'm still struggling with this.
Here's few gems I've added in my Gemfile to benchmark my app:
gem 'airbrake'
gem 'newrelic_rpm'
gem 'stackprof'
gem 'derailed', group: :development
gem 'rack-mini-profiler'
gem 'flamegraph'
gem 'memory_profiler'
gem "skylight"
After a lots of benchmarks in development and in staging env, I know where my app is not fast enough but there's not memory leak (some small mem bloats sometimes maybe).
newapp-staging app is the new version (aka: new frontend, upgraded gems, optimized queries, ...) of oldapp-production app.
Please have a look at the screenshots (oldapp-production use webrick, newapp-staging use puma)
So here comes 2 simple questions:
question #1
newapp-staging app is using ruby '2.2.0' & rails '3.2.22.2' and I can't ensure that it is threadsafe because of my code and the associated gems, so... I must use 1 thread at a time. Is puma an advantage here? Metrics are telling me not.
OR... my configuration is not good. (missing preload_app! maybe, or other things?) Here's my Procfile:
web: bundle exec puma -t 1:1 -p ${PORT:-3000} -e ${RACK_ENV:-development}
worker: bundle exec rake jobs:work
question #2
Unicorn could be used as a replacement?
Thank you for your time and your advices.
Cheers
Using unicorn is the best move here. Here's my configuration if that could help anyone.
Gemfile:
gem 'unicorn'
gem 'unicorn-rails'
group :production, :staging do
gem 'unicorn-worker-killer'
end
Procfile:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 2)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
config.ru
if ENV['RAILS_ENV'] == 'production' || ENV['RAILS_ENV'] == 'staging'
require 'unicorn/worker_killer'
use Unicorn::WorkerKiller::MaxRequests, 768, 1024, true
use Unicorn::WorkerKiller::Oom, (450*(1024**2)), (490*(1024**2)), 16, true
end
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run MyApp::Application
On Heroku:
2 x `Standard 2X dynos` for web
1 x `Standard 1X dyno` for worker
Heroku config vars:
SENSIBLE_DEFAULTS: enabled (just in case) & WEB_CONCURRENCY: 2
Cheers

Define Bundle Path With Capistrano

I am using the following configurations in my deploy.rb file for capistrano:
require 'bundler/capistrano'
require 'rvm/capistrano'
set :bundle_cmd, "/home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle"
set :default_environment, {
'PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194/bin:/home/deployment/.rvm/bin:$PATH",
'RUBY_VERSION' => 'ruby 1.9.3',
'GEM_HOME' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194",
'GEM_PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194",
'BUNDLE_PATH' => "/home/deployment/.rvm/gems/ruby-1.9.3-p194"
}
But when I run cap deploy:update I get this:
* executing "cd /var/www/currienet/marketplace/releases/20120928140140 && /home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle install --gemfile /var/www/currienet/marketplace/releases/20120928140140/Gemfile --path /var/www/currienet/marketplace/shared/bundle --deployment --quiet --without development test"
That is, it's not setting the bundle path (the --path argument) to what I want it to be.
I've tried a number of tutorials, including the rvm capistrano tutorial but nothing seems to work. It continues to use the capistrano default.
Capistrano also creates an application with the following .bundler/config
BUNDLE_FROZEN: '1'
BUNDLE_PATH: /var/www/currienet/marketplace/shared/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_WITHOUT: development:test
Development Machine: Windows 7, bundler (1.0.22), capistrano (2.12.0), rvm-capistrano (1.2.7), rails (3.2.8), (no rvm)
Production: Debian, bundler (1.2.1) (no capistrano), (no rvm-capistrano), rails (3.2.8), rvm 1.16.5
Thanks to Joseph Holsten's blog I was able to ascertain my problem was I was not defining the bundler variables in my deploy.rb before I required 'bundler/capistrano'. I also needed to define the bundle_dir variable, to create code that looks like the following:
set :bundle_cmd, "/home/deployment/.rvm/gems/ruby-1.9.3-p194#global/bin/bundle"
set :bundle_dir, "/home/deployment/.rvm/gems/ruby-1.9.3-p194"
require 'bundler/capistrano'

Rails 3.2 + minitest + sqlite3 :memory: = Fail

I'm unable to use the :memory: database with Rails 3.2, sqlite3, and minitest. I have the following in database.yml:
test:
adapter: sqlite3
database: ":memory:"
and get the following error when doing rake minitest
/home/hoffmanc/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/connection_adapters/sqlite_adapter.rb:465:in `table_structure': Could not find table 'apks' (ActiveRecord::StatementInvalid)
(one of my models is named Apk)
Am I missing a step?

Capistrano can't find a JavaScript runtime

I have a problem with Capistrano deploying to a server with RVM and gemsets
executing `deploy:assets:precompile'
* executing "cd /var/app/releases/20111229233555 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile"
*** [err ::] rake aborted!
*** [err ::] Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
*** [deploy:update_code] rolling back
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2#mygemset' -c 'cd /var/app/releases/20111229234715 && rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'"
This is my Capfile
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :rvm_bin_path, "$HOME/.rvm/bin"
set :rvm_ruby_string, '1.9.2#mygemset'
set :rvm_type, :user
load 'deploy/assets'
When I log in as the very same user which is used by Capistrano the failing command is executed without any problems.
It seems that Capistrano is using some other environment.
Here is my ~/.rvmrc file:
rvm_gemset_create_on_use_flag=1 rvm_trust_rvmrcs_flag=1
Is there a way how to check which ruby and gemset is used at the execution time?
node.js is and V8 are installed on the system, and all needed gems are in Gemfile:
here is my rvm info:
ruby:
interpreter: "ruby"
version: "1.9.2p290"
date: "2011-07-09"
platform: "x86_64-linux"
patchlevel: "2011-07-09 revision 32553"
full_version: "ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]"
homes:
gem: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset"
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290"
binaries:
ruby: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/ruby"
irb: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/irb"
gem: "/home/capistrano/.rvm/rubies/ruby-1.9.2-p290/bin/gem"
rake: "/home/capistrano/.rvm/gems/ruby-1.9.2-p290#mygemset/bin/rake"
setting up PATH in the deploy.rb solved this issue:
default_environment['PATH'] = "/usr/local/bin:/usr/bin:/bin:/opt/bin:$PATH"
it's a Gentoo distribution and the PATH var seems to be empty when using cap deploy, so I copied the content of server PATH and now it works
This issue went away for me when I installed nodejs (using apt-get) on my server. As I stated in this Stackoverflow answer, it's the most practical choice because you don't need to include any dependencies in your Gemfile.