I am fairly new to Ruby on Rails and am currently having a problem with configuring config/database.yml to connect Oracle XE 11g R2. I need your help!
Here is my setup:
VirtualBox 4.3.6
Ubuntu 64 v12.04.3
$ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
$ rails -v
Rails 4.0.2
$ gem -v
2.2.2
$ gem install ruby-oci8
Building native extensions. This could take a while...
Successfully installed ruby-oci8-2.1.7
Parsing documentation for ruby-oci8-2.1.7
Done installing documentation for ruby-oci8 after 4 seconds
1 gem installed
# Oracle XE 11gR2 installed in a different VM (Host: 10.1.1.3)
#
$ ruby -r oci8 -e 'OCI8.new("ruby/ruby#10.1.1.3").exec("select * from session_privs") do |r| puts r.join(","); end'
CREATE SESSION
UNLIMITED TABLESPACE
CREATE TABLE
CREATE CLUSTER
CREATE SEQUENCE
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
CREATE OPERATOR
CREATE INDEXTYPE
Note that I can verify connection using the command above. However, I cannot create a new model using the "rails generate model Post title:string text:text" command - I get a long list of errors which complain that my "adapter" is not valid.
Questions:
Q1. What do I have to put in the Gemfile?
Q2. Should I see ruby-oci8 gem in the output of the command "bundle install" - currently I can see "Using sqlite3 (1.3.9) and there also 2 entries in the Gemfile as follows:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
Q3. Has anyone successfully configured database.yml to work with Oracle XE? Please share it with me.
Thanks in advance for your help,
Roobie
Having ruby-oci8 installed is often the hard bit, so you're nearly there.
Activerecord needs an adapter to talk to any kind of database; for oracle you will want oracle enhanced.
So add this to your Gemfile then redo bundle install:
gem 'activerecord-oracle_enhanced-adapter'
Read the linked page for oracle-specific quirks. Your database.yml file should look like this:
database:
adapter: oracle_enhanced
database: //10.1.1.3:1521/XE
username: ruby
password: ruby
The "XE" in the database connection string is the SID. I think with oracle XE the SID is always "XE" but I don't have one handy and haven't used it since 10g.
You shouldn't need to add ruby-oci8 to your gemfile because the oracle adapter declares it as a dependency, but it doesn't hurt to add it.
Related
I'm trying to set up my local dev environment to match my team's. I can't upgrade Ruby/Rails/mysql2 (for the time being).
I know my local MySQL config is good (enough?) because I can create a new Rails project and run it just fine. I'm getting the same error if I run rake db:create or rails s or even start IRB and run require 'mysql2'.
I've googled the hell out of this. I was initially using MariaDB as my MySQL implementation locally, so I thought that might be screwing with the mysql2 gem. So I ripped out MariaDB and finally got MySQL 5.6 working (another team version we're locked into at the moment). After successfully upgrading to MySQL 5.6, I'm confident that's 100% not the issue.
I would expect if I had the wrong password for it to complain about the config somehow, but it's always the same.
uninitialized constant Mysql2::Client::SECURE_CONNECTION
Ruby (RVM): ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
Mysql2: 0.3.16
There have been some other version-related struggles, but nothing this strong. The only thing I've encountered that I haven't actually tried is building the mysql2 gem locally.
I would expect require 'mysql2' to at least load the gem. Neither Rails nor Rake will work with the gem at all. It's almost like it's missing some internal file.
following as discussion about this error in official gem, you should update version as
From
gem 'mysql2', '0.3.16'
to
gem 'mysql2', '0.3.17'
if you still met an error after you update version to 0.3.17, i think that you should update to 0.2.24
https://github.com/brianmario/mysql2/issues/603
I am a beginner in rails development. till now I was creating small modules using, sqlite3 now I want to convert it to PostgreSQL please help me with step by step procedure.
First you need to install postgres in your OS.
Then replace gem 'sqlite3' to gem 'pg' in Gem file.
Then bundle install command need to run.
Or you can directly create a project through rails new my_app_name --database=postgresql command
I am new to ruby on rails development. I am currently having difficulties generating a new rails controller. here is what I input into the terminal:
$ rails generate controller static_pages home help
here is the response I receive:
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/connection_specification.rb:177
:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded.
Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
I am also using Heroku for production so I initially removed sqlite3 because Heroku cant use it by doing:
$ gem uninstall sqlite3
and I removed it from my gemfile and gemfile.lock. Was this a mistake? Any guidance would be much appreciated.
The error is because the config/database.yml file still has sqlite3 as the database adapter for the development database.
If you know which database you want to use for your local development database, set the appropriate database adapter in this file.
Heroku can't use sqlite3; however, you can use sqlite3 for your local development database, and specify postgres or mysql for production database.
Since you are a total beginner, I would recommend following the steps from a detailed tutorial as it is till you become familiar with the various concepts. Michael Hart's Rails Tutorial book is available for free online, and is a very good resource for beginner rails developers.
you cold try to rm Gemfile.lock and bundle install to reinstall your gems
Also make sure that the sqlite3 gem is in the development group
gem 'sqlite3', :group => :development
So that it will not be install on Heroku
In my Rails app,I need to use oracle database.I installed the oracle 11g client successfully.I can connect the oracle server through:
sqlplus SFUSER/sfuser#SF
Then I connect oracle in Rails:
In databse.yml:
development:
adapter: oracle_enhanced
database: 192.168.0.154/SF
username: SFUSER
password: sfuser
In my Gemfile,I add
gem 'activerecord-oracle_enhanced-adapter', '~> 1.5.4'
gem 'ruby-oci8', '~> 2.1.7'
and run bundle install
All gem are installed successfully.
But when I run:
rails s
I got:
/home/hxh/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-oracle_enhanced-adapter-1.5.4/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb:67:in `<top (required)>': uninitialized constant ActiveRecord::ConnectionAdapters::ColumnDumper (NameError)
I had exactly the same problem. I found this from activerecord-oracle_enhanced-adapter github pages
Oracle enhanced adapter version 1.5 just supports Rails 4 and does not
support Rails 3.2 or lower version of Rails.
...
When using Ruby on Rails version 3 then in Gemfile include
gem 'activerecord-oracle_enhanced-adapter', '~> 1.4.0'
After running bundle install, rails s started to work.
Nubie at Ruby on Rails so I wanted to build a "Hello World" style of app to get familiar with RoR. The app I chose, along with tutorial on installation, was Dave Berube's "checkbook" app as in http://www.redhat.com/magazine/025nov06/features/ruby/
Yes it is from 2006 and maybe I have bumped into my errors because RoR has moved on through the years. Anyway, I get errors similar to banditKing with his app on 20th Sept., and many others; I get a persistent error as below.
When I ran RoR without creating my first app, it displayed the initial splash screen which effectively told me to "get working and create sites!" so that was a good start :-)
[running "rails generate migrate InitialSchema" to begin generating the application framework.]
/usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
from /usr/local/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `<top (required)>'
My environment:
RH Enterprise Linux version 6, 64-bit
[root#svr checkbookapp]# which mysql
/usr/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.1.69 Source distribution
[root#svr checkbookapp]# which ruby
/usr/local/bin/ruby
[root#svr checkbookapp]# ruby -v
ruby 2.0.0p247 (2013-06-27) [x86_64-linux]
Rails version is 4.0.0
[root#svr checkbookapp]# gem list | grep mysql
mysql (2.9.1)
mysql2 (0.3.13)
Start of my app's Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'mysql2'
...
I have added the library path to MySQL path into my .bash_profile as done by banditKing but that has not resolved this error. Have tried re-installing mysql2 gem several times and doing numerous "bundle install" operations. Downloaded and installed the connector 6.1 from the MySQL site and yum install'd the share and the development versions without any difference.
Try updating RubyGems with gem update --system. You should get something like version 2.x. There's a bug with RubyGems 1.8.x on Ruby 2.0 installing gems with c extentions (like mysql2 and nokogiri).