I am trying to deploy my first rails application on digital ocean in Ubuntu, I am unsure if I am doing this right. I initially had my production database in postgres and test and production in sqllite. In frustration, I changed all my databases to postgres my changing the database.yml. I am unsure if I did that correctly But I had this error: ActiveRecord::StatementInvalid (SQLite3::ReadOnlyException: . When I was in sqllite. I was not sure if I had to tell the server to switch to production mode or if it was configured to use sqllite.
What I want to do is use postgres instead of sqllite. I am using nginx and Unicorn. MY database is blank so I dont need to transfer anything. I have made the postgres database within postgres, I just need to point my app to that database. (I am unaware if I need to do something else
I have used this database.yml
development:
adapter: postgresql
encoding: unicode
host: localhost
database: blog_development
pool: 5
username: bob
password: password
test:
adapter: postgresql
encoding: unicode
database: blog_test
host: localhost
pool: 5
username: bob
password: password
production:
adapter: postgresql
encoding: unicode
host: localhost
database: blog_production
pool: 5
username: bob
password: password
Gem file:
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.4'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'bootstrap-sass' # for using bootstrap-rails"
gem 'faker'
gem 'will_paginate'
gem 'annotate', '~> 2.6.5'
gem 'font-awesome-rails' # for using font-awesome icons
gem 'redcarpet', '~> 2.1.1'
gem 'coderay', '~> 1.1.0' # For nice code snippets
gem 'devise'
gem 'sidekiq'
gem 'haml-rails'
group :development do
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'guard-rspec'
end
group :test do
gem 'capybara'
gem 'factory_girl_rails', '4.2.0'
end
gem 'pg', '0.15.1'
group :development, :test do
gem 'rspec-rails'
# Use sqlite3 as the database for Active Record in testing
end
group :production do
gem 'rails_12factor', '0.0.2'
end
I have the rest of the code on my github: https://github.com/RubyQuarry/Bootstrap_blog
Run rake db:drop db:create db:drop to drop your old database(s) and recreate the new ones in Postgres.
Related
I need to connect to a SQL Server database, I installed gem 'tiny_tds' gem 'activerecord-sqlserver-adapter' gem 'deprecated'
my yml file:
default: &default
adapter: sqlserver
host: basddatos.dyndns.org
username: zu
password: pass
pool: 5
timeout: 5000
development:
<<: *default
database: Basdatos_2016
GEMFILE
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
#SQl Server
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter'
gem 'ruby-odbc'
gem 'deprecated'
gem 'dbd-odbc'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
I get this error: TinyTds::Error Server name not found in configuration files
WHY? thanks
This isn't a full answer but a debugging suggestion (I needed the example space). Try setting the development block in your database.yml to:
development:
adapter: sqlserver
host: basddatos.dyndns.org
username: zu
password: pass
pool: 5
timeout: 5000
database: Basdatos_2016
Do you still get the same error?
I got my Rails 4 app running on my local machine and on heroku at the moment. Now I tried to set up an ubutunu 14 server. For deployment I am using capistrano and the connection between my local machine and the server is already set. Currently I am trying to do the initial deploy with this command:
cap production deploy:initial
I get following error at a certain point:
Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on MYIP
DEBUG Command: cd /home/deploy/apps/savoir/releases/20160209113448 && ( export RAILS_ENV="production" ; ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG rake aborted!
DEBUG Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
My gemfile looks like this:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.1'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
gem 'bootstrap-sass', '~> 3.3.5.1'
gem 'autoprefixer-rails'
gem 'bootstrap-sass-extras'
gem 'bootstrap-daterangepicker-rails'
gem 'bootstrap-datepicker-rails'
gem 'simple_form'
gem 'nested_form'
gem 'ckeditor'
gem 'coffee-script-source', '1.8.0'
gem 'carrierwave', github:'carrierwaveuploader/carrierwave'
gem 'carrierwave-crop'
gem 'rmagick'
gem 'mini_magick'
gem 'momentjs-rails'
gem 'gon'
gem 'jquery-ui-rails'
gem 'jquery-fileupload-rails'
gem 'jquery-turbolinks'
gem 'jquery-validation-rails'
gem 'devise'
gem 'ransack'
gem 'will_paginate'
gem 'rails_12factor'
gem 'pg', '~> 0.18.3'
gem 'geocoder'
gem 'gmaps4rails'
gem 'underscore-rails'
group :development do
gem 'capistrano', require: false
gem 'capistrano-rvm', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano3-puma', require: false
end
gem 'puma'
And my database.yml:
development:
adapter: postgresql
database: savoir_development
pool: 5
username: postgres
password: root
test:
adapter: postgresql
database: savoir_test
pool: 5
timeout: 5000
username: postgres
password: root
production:
adapter: postgresql
database: deploy
pool: 5
timeout: 5000
username: USER
password: PASSWORD
So as far as I can see it, the gemfile and database.yml should be fine. Can anyone find the mistake(s) I made? I found a few other threads that worked this topic but they didn't help in my case.
Ok, I found the solution.
Since I was using windows on my local machine, rails used this version of pg:
//Gemlock.lock
pg (0.18.4-x86-mingw32)
Changing it to
//Gemlock.lock
pg (0.18.4)
and pushing it to the git solved my problem.
i can push to heroku just fine.. however when I run a rake i get this error:
PG::ConnectionBad: could not connect to server
I can run locally ok so not really sure why I am having trouble pushing to heroku - any help would be great
I suspect this is related to my database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# 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:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
Also here is my gemfile:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
group :development do
gem 'sqlite3'
gem 'capistrano'
end
group :production do
gem 'pg'
gem 'mysql2'
gem 'activerecord-mysql-adapter'
gem 'rails_12factor'
end
# Use SCSS for stylesheets
gem 'coffee-rails'
gem 'bootstrap-sass', '~> 3.3.3'
gem 'sass-rails', '>= 3.2'
gem 'autoprefixer-rails'
gem 'will_paginate', '~> 3.0.7'
gem 'will_paginate-bootstrap'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
You should not commit database.yml into heroku:
When Rails applications are deployed to Heroku a database.yml file is
automatically generated for your application that configures
ActiveRecord to use a PostgreSQL connection and to connect to the
database located at DATABASE_URL. This behavior is only needed up to
Rails 4.1. Any later version contains direct support for specifying a
connection URL and configuration in the database.yml so we do not have
to overwrite it.
Read heroku documentation about this.
I'm trying to connect to an SQL Server 2012 database from a Ruby on Rails application. I get this error when running the rake command. Am I supposed to run the command bundle install every time I install a new gem? I'm not sure why I'm getting the error below NoMethodError: undefined...
rake db:schema:dump RAILS_ENV=development
rake aborted!
NoMethodError: undefined method `info_schema_query' for #<ActiveRecord::ConnectionAdapters::SQLServerAdapter:0x007fba899762b0>
Tasks: TOP => db:schema:dump
This is my database.yml file
default: &default
adapter: sqlserver
encoding: utf8
port: 1433
pool: 5
username: myuser
password: secretpassword
socket: /tmp/mysql.sock
host: 184.168.194.51
development:
<<: *default
database: mydbname
test:
<<: *default
database: mydbname
production:
<<: *default
database: simple_cms_production
username: simple_cms
password: <%= ENV['SIMPLE_CMS_DATABASE_PASSWORD'] %>
This is in my Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
gem 'tiny_tds', '~> 0.6.2'
gem 'sql_server', '~> 0.1.1'
gem 'activerecord-sqlserver-adapter', '~> 4.1.0'
gem 'activerecord-sqlserver-adapter-schemas', '~> 1.0.2'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
I'm trying to teach myself ruby on rails and I'm trying to create a simple application to start with. I'm following the tutorial at http://guides.rubyonrails.org/getting_started.html#creating-a-new-rails-project but am having difficulty starting the server. When I try start up the server and go to the localhost,
Could not load 'active_record/connection_adapters/sqlite3_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.
I'm tried to look up a solution/reason why this happens on other questions but to no avail.
My Gemfile looks like this
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:
https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
I'm using
Ruby 2.1.3
and when I type
gem list
I find I'm running
rails 4.1.6
sqlite3 (1.3.9 x86-mingw32)
Can anyone point me in the right direction?
Make sure your config/database.yml has an appropriate database driver set for current environment:
development:
adapter: sqlite3 # check if you have sqlite3 here
encoding: ...
database: ...
pool: ...
username: ...
password: ...
Also don't forget to set it for all other environments you want to use sqlite3 in.
I've never used sqlite but from the error I'm guessing you have a line in database.yml that says:
adapter: sqlite3_adapter
that should instead be:
adapter: sqlite3
Edit: ninja'd
You can put your sqlite3 gem to development in Gemfile
group :development do
gem 'sqlite3'
//*Your other gem to only development
end
wrong adapter in your database.yml file.
use this:
adapter: sqlite3