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
Related
I'm working on ruby on rails project on hosting machine "nitrous"
I'm trying to push my files on Heroku using command
git push Heroku master</code>
and this is the building log:
note: building log is really big mess all what you need is to read site
Docs to know what they really support before trying to install
something
Heroku does not support sqlite3. It instead uses a PostgreSQL database. I'd recommend following these docs for deploying Rails apps to Heroku:
Rails 4: https://devcenter.heroku.com/articles/getting-started-with-rails4
Rails 5: https://devcenter.heroku.com/articles/getting-started-with-rails5
It's as easy as going to your Gemfile and changing gem 'sqlite3' to gem 'pg'. Be sure to run bundle afterwards.
You'll then need to set up a simple database.yml file, and then rebuild your schema for local development.
Follow the docs and you'll be fine.
in youe gemfile
gem 'pg'
group :development do
gem 'sqlite3'
end
then
bundle install
push Gemfile and Gemfile.lock to git.
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.
I downloaded an archive containing code for a Rails application ( from a book I'm reading ). I'm running Rails 3.0.1 but the application fails to start, because it's looking for 3.0.0beta3. Is there some way of starting it with my version of Rails?
Yes, look for the Gem file in the application root and look for the line
gem 'rails', '3.0.0beta3' and change it to
gem 'rails', '3.0.1'
then run bundle install from a terminal in your application root.
this is because your Gemfile.lock is probably showing Rails 3.0.0.beta3. Even if you change your Gemfile to 3.0.1 AND install it using gem install rails, you will need to run bundle install or bundle update rails
There is probably a line in the environment.rb file that looks like
RAILS_GEM_VERSION = '3.0.0beta3' unless defined? RAILS_GEM_VERSION
Updating this should sort your issue.
to clarify: there's only one rails command, which gets installed from the latest Rails gem, which is Rails 3 ATM. However, I'm required to create a Rails 2.3 app.
Running ruby /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.8/bin/rails fails with a NoMethodError, I suppose because it also tries to use gems from the 3.0.0 release.
Uninstalling the gem produces some strange results:
$ gem uninstall rails-3.0.0
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rails-3.0.0`
$ gem list -d rails-3.0.0
*** LOCAL GEMS ***
(and no gems here)
What should I do?
The easiest way to do it was:
Create the directory for the project
Create a Gemfile there containing
gem "rails", "2.3.9"
gem "sqlite3-ruby", :require => "sqlite3"
Run bundle install
Run bundle exec rails . to create an app in the current path
You don't even need rvm to do this.
(I assume 2.3.11, given it's the latest)
rails _2.3.11_ new app will do this for you without you having to muck about.
(Had to make a comment since I don't have enough Stack Overflow cred and can't directly respond to answers yet.)
For folks running rails 3 now the "new" command is now required for creating new rails applications. As such "new" will need to be appended to the end of the commands.
So for Leonid Shevtsov's answer, Step 4: bundle exec rails new .
And for Robert Speicher's answer: rails new .
Install rvm and then create a new gemset, so that Rails 2 is isolated.
Or, go to the directory where you want your Rails 2 app to be, create a Gemfile like a Rails 3 app, but specify gem "rails", "~> 2.3" and run bundle install, and you should now be able to issue rails .