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.
Related
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
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.
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).
My rails applications run on a shared host. I don't have access to a commandline and can't run the bundle command. I can run a few pre-selected rake commands.
On my development machine, I've done bundle install --deployment, so that all my gems are in vendor/bundle.
Problem is, however, that my development machine is not compatible with my shared host (32/64 bits), so the native extension of the mysql2 gem doesn't work on the shared host. The shared host does have the mysql2 gem installed, though.
If I remove 'mysql2' from the Gemfile, I get this error: !!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2' (<= this was because I had the adapter set to mysql instead of mysql2 in database.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: db
pool: 5
username: user
password: pass
socket: /var/run/mysqld/mysqld.sock
(same for test/production)
If I keep gem 'mysql2' in my Gemfile, I get this error (which makes sense, because of the native extension was compiled on a different machine:
/home/project/vendor/bundle/ruby/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.so: wrong ELF class: ELFCLASS32 - /home/project/vendor/bundle/ruby/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.so
If I remove gem 'mysql2', I get:
Please install the mysql2 adapter: 'gem install activerecord-mysql2-adapter' (no such file to load -- active_record/connection_adapters/mysql2_adapter)
I would like to specify which gems should be loaded from my own applications vendor/bundle directory and which gems from the system gem directory.
Is this possible with bundler?
What's the best solution for this problem?
Thanks.
Check your database.yml file. Make sure you are not referring to the adapter that you don't have installed in your environment.
Have you checked your gemlock file for -x86 gem references? I had a similar issue deploying from windows xp to 64-bit ubuntu. Modify these to remove the -x86 part and run bundle install again, this should build the 64-bit native gem if all the libraries are on the instance.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
ruby mysql2 gem installation issues
I have worked with ruby on rails with mysql2 database. I have installed the the mysql2 gem in my system. I successfully configure my database my database.yml file which is
development:
adapter: mysql2
database: AddressBook
username: root
password: root
host: localhost
pool: 5
timeout: 5000`
but the issues are
When i tried to create my model using the command rails g model contact it shows an error
"Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (no such file to load -- active_record/connection_adapters/mysql2_adapter) (RuntimeError)"
like this.
So in order to install mysql2 i have execute the command gem install mysql2. It shows 1 gem installed with a message of "Enclosing class/module 'mMysql2' for class Client not known"
And one more thing, after installing mysql2 gem file if i am check the existence of mysql2 using command
which mysql2
it again shows no mysql2 is installed with a message
"/usr/bin/which: no mysql2 in (/usr/lib/ccache:/usr/lib/ccache:/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/zoondia001/bin)"
If ruby on rails database connection is not possible with mysql2 please tell me another way to connect ruby on rails to database
i am using fedora 13 and installed ruby,ruby on rails and all the gems that are needed for running. Anybody please tell me how track this problem, i am nearly spend my 48 hours for tracking this issues but not getting the solution. please help me
thanks
Add
gem 'mysql2', '< 0.3'
in gemfile
Finally it is corrected. I have remove ruby,rails and gem from system and re-install again. Any way thanks for the help