Installing PostgreSQL with Ruby on Rails on Mac OS X - ruby-on-rails-3

I have everything installed. But when I run "rake db:create", I get the following:
Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)
rake aborted!
no such file to load -- pg
Here is my database.yml:
development:
adapter: postgresql
encoding: unicode
database: sixmonths_development
pool: 5
username: postgres
password: xxxxxxxx
test:
adapter: postgresql
encoding: unicode
database: sixmonths_test
pool: 5
username: sixmonths
password: xxxxxxxx
production:
adapter: postgresql
encoding: unicode
database: sixmonths_production
pool: 5
username: sixmonths
password: xxxxxxxx
I can see pg is installed when I run: gem list
I tried replacing "postgresql" with "pg" per another post on stackoverflow, but it resulted in this:
Ken-Vogts-MacBook:sixmonths ken$ rake db:create
(in /Users/ken/sixmonths)
Seems cool, right?
Nope. Next, I try "rake db:schema:dump" and I get this:
Ken-Vogts-MacBook:sixmonths ken$ rake db:schema:dump
(in /Users/ken/sixmonths)
rake aborted!
Please install the pg adapter: `gem install activerecord-pg-adapter` (no such file to load -- active_record/connection_adapters/pg_adapter)
Of course there is no "activerecord-pg-adapter". What do I have to do to make this work?
Gemfile Contents:
source 'rubygems.org'
gem 'rails', '3.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'unicorn'
# gem 'capistrano'
# gem 'ruby-debug'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end

Rails 3 will only let you access the gems you specify in your Gemfile, so even if you have it installed in your system-wide gems by doing a gem install pg, it won't be able to find it.
Add gem 'pg' to your Gemfile, run bundle install, and you should be good to go.

I tried many things that I saw as solutions elsewhere, but the only thing that worked for me was replacing
gem 'sqlite3'
with
gem 'pg'
in Gemfile. My database.yml looks the same as yours.
Now both >rake db:create and >rake db:migrate work.
This is on OSX Snow Lepoard, Rails 3.0.7, Postgres 9.0.
And the output from:
gem list --local
is
pg (0.11.0)
polyglot (0.3.1)
postgres-pr (0.6.3)
rack (1.2.2, 1.0.1)
rack-mount (0.7.2, 0.7.1, 0.6.14)
rack-test (0.6.0, 0.5.7)
rails (3.0.7, 3.0.5, 2.3.5, 2.2.2, 1.2.6)

Related

Ruby on Rails Passenger on Apache gemfile syntax Error ID 506682d5

Running Rails 4 on Apache2 using Phusion Passenger and Ruby 2.1 installed via RVM. When I access the Rails app in the browser, I get this error:
Gemfile syntax error compile error
on line 24: syntax error, unexpected ':', expecting $end
gem 'sdoc', '~> 0.4.0', group: :doc
^ (Bundler::GemfileError)
/home/romistrub/.rvm/gems/ruby-2.1.3#global/gems/bundler-1.7.3/lib/bundler/dsl.rb:35:in `eval_gemfile'
/home/romistrub/.rvm/gems/ruby-2.1.3#global/gems/bundler-1.7.3/lib/bundler/dsl.rb:10:in `evaluate'
/home/romistrub/.rvm/gems/ruby-2.1.3#global/gems/bundler-1.7.3/lib/bundler/definition.rb:25:in `build'
/home/romistrub/.rvm/gems/ruby-2.1.3#global/gems/bundler-1.7.3/lib/bundler.rb:154:in `definition'
/home/romistrub/.rvm/gems/ruby-2.1.3#global/gems/bundler-1.7.3/lib/bundler.rb:117:in `setup'
/home/romistrub/.rvm/gems/ruby-2.1.3#global/gems/bundler-1.7.3/lib/bundler/setup.rb:17
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `gem_original_require'
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:263:in `run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158
Error ID
506682d5
Rails app gemfile:
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
# 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]
the command
cat $(which bundle)
gives
#!/usr/bin/env ruby_executable_hooks
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0"
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
version = $1
ARGV.shift
end
end
gem 'bundler', version
load Gem.bin_path('bundler', 'bundle', version)
command
rake about
gives
About your application's environment
Ruby version 2.1.3-p242 (x86_64-linux)
RubyGems version 2.2.2
Rack version 1.5
Rails version 4.1.6
JavaScript Runtime Node.js (V8)
Active Record version 4.1.6
Action Pack version 4.1.6
Action View version 4.1.6
Action Mailer version 4.1.6
Active Support version 4.1.6
Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, # <ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x00000004ec86d8>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, Rack::Head, Rack::ConditionalGet, Rack::ETag
Application root /var/www/board/demo
Environment development
Database adapter sqlite3
Database schema version 0
I have no idea where to even start with this one.
Any help is greatly appreciated. Thanks in advance.
Turns out it was an issue with Passenger on RVM, wherein Passenger was using the wrong ruby binary.
After making sure I was using the right Ruby in RVM via
ruby use 2.1
then checking that I was using the proper PassengerRuby directive in Apache using
passenger-config --ruby-command
then changing the Apache configuration to the result of the above command:
PassengerRuby /home/<user>/.rvm/gems/ruby-2.1.3/wrappers/ruby
everything worked.
Well, almost. I encountered another error: a missing SECRET_KEY_BASE ENV. To fix that, I added to the /etc/apache2/envvars the following line:
export SECRET_KEY_BASE=<thisisthesupersecretsecretkeypleasedontcopy>
And restarted apache. Now my only problem is the following error, which I hope has a basic fix:
The page you were looking for doesn't exist.

Trouble Deploying to Heroku

Alright, I'm new to this and really need some guidance here.
I cannot deploy to Heroku to save my life and have been at it for 8 hours and read every stackoverflow and google post I can find.
Ruby Version ----> ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
Rails Version ----> Rails 4.0.0
PostgreSQL ----> psql (PostgreSQL) 9.3.4
Here's what I have going on:
$ git push heroku master
Initializing repository, done.
Counting objects: 62, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (51/51), done.
Writing objects: 100% (62/62), 14.40 KiB | 0 bytes/s, done.
Total 62 (delta 3), reused 0 (delta 0)
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.6.3
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Fetching gem metadata from https://rubygems.org/..........
Fetching additional metadata from https://rubygems.org/..
Installing...etc etc etc
Now I get this...
Your bundle is complete!
Gems in the groups development and test were not installed.
It was installed into ./vendor/bundle
Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!
Bundle completed (11.95s)
Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.
This is what my Gemfile looks like:
source 'https://rubygems.org'
gem 'rails', '4.0.0'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
gem 'rails_12factor', group: :production
group :assets do
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
end
And here is my database.yml
development:
adapter: postgresql
database: rails_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: rails_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: rails_production
pool: 5
timeout: 5000
Type this in your command line: 'gem list'... Let me know if you see 'sqlite3' in the returned list of gems.
Also, put rails_12factor inside your production bloc like so:
group :production do
gem 'pg'
gem 'rails_12factor'
end
Also, add this gem to your development group, and make sure you run bundle install after:
gem 'factory_girl_rails', '~> 4.0'
To minimise differences between development and production (Heroku) I used the Postgresql database in all my environments.

Enki deployment to Heroku - problems with assets precompile

I cloned this https://github.com/xaviershay/enki and did the following modifications:
My Gemfile now looks like this:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
end
group :production do
gem 'pg'
end
group :development do
gem 'mysql2', '~> 0.3.11'
end
platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter'
gem 'trinidad'
gem 'jruby-openssl'
end
gem 'jquery-rails'
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug'
# Bundle the extra gems:
gem 'RedCloth', '~> 4.2.9', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem 'rack-openid', :require => 'rack/openid'
gem 'aaronh-chronic', :require => 'chronic' # Fixes for 1.9.2
gem 'coderay'
gem 'lesstile'
gem 'formtastic'
gem 'will_paginate', '~> 3.0.2'
gem 'exception_notification', '~> 2.5.2'
gem 'open_id_authentication'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :test do
gem 'database_cleaner'
gem 'cucumber-rails', :require => false
gem 'cucumber-websteps', :require => false
gem 'factory_girl'
gem 'rspec'
gem 'nokogiri', '~> 1.5.0'
gem 'webrat'
end
group :development, :test do
gem 'rspec-rails'
end
And I also modified the database.yml file to look like this:
development:
adapter: mysql2
database: myblog_development
username: root
password:
host: localhost
test:
adapter: mysql2
database: myblog_test
username: root
password:
host: localhost
I am able to check the site in my local, but when trying to deploy to Heroku I get the following:
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
Tasks: TOP => environment
(See full trace by running task with --trace)
Precompiling assets failed, enabling runtime asset compilation
Injecting rails31_enable_runtime_asset_compilation
Please see this article for troubleshooting help:
http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
I tried doing what they suggest in that last site, but still getting the same error. What am I missing?
In your application.rb file, add this line:
config.assets.initialize_on_precompile = false

Deploying to Rails project to Heroku: Could not find activemodel

I am relatively new to rails and have been working my way through the Michael Hartl Tutorial. Throughout I have been deploying my projects to Heroku, however now I am at the end of chapter 5, I am getting an "application error". Specifically I am getting the following errors when I look into my Heroku logs:
2012-01-04T03:05:04+00:00 app[web.1]: Could not find activemodel-3.2.0.rc1 in any of the sources
2012-01-04T03:05:06+00:00 heroku[web.1]: State changed from starting to crashed
2012-01-04T03:05:06+00:00 heroku[web.1]: Process exited
2012-01-04T03:05:11+00:00 heroku[router]: Error H10 (App crashed) -> GET floating-stone 5077.heroku.com/ dyno= queue= wait= service= status=503 bytes=
Earlier in the log I see the following errors as well:
WARNING: Invalid .gemspec format in '/app/.bundle/gems/ruby/1.9.1/specifications/rails-3.2.0.rc1.gemspec'
WARNING: Invalid .gemspec format in '/app/.bundle/gems/ruby/1.9.1/specifications/actionmailer-3.2.0.rc1.gemspec'
WARNING: Invalid .gemspec format in '/app/.bundle/gems/ruby/1.9.1/specifications/actionpack-3.2.0.rc1.gemspec'
my gemfile is as follows:
source 'https://rubygems.org'
gem 'rails', '3.2.0.rc1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.0'
gem 'coffee-rails', '~> 3.2.0'
#gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
group :development do
gem 'rspec-rails', '2.7.0'
gem 'ZenTest', '4.6.2'
gem 'autotest-growl'
gem 'autotest-fsevent'
gem 'webrat', '0.7.3'
end
group :test do
gem 'rspec', '2.7.0'
gem 'webrat', '0.7.3'
end
I am having trouble debugging the issue and looked through almost all of the rails/heroku posts I could find but nothing on this specific issue. I was looking for some help...apologies if this is something quite basic.
I should also mention that the app works fine on my local machine and here is my database information (I am using mysql). Here is the DB info.
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: sample_app_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
# 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: mysql2
encoding: utf8
reconnect: false
database: sample_app_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: sample_app_production
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Thanks!
The live version of new rails is available now ... i think you should give a try to rails 3.1.3 mature version ... this seem to come configuration issue as i am running my apps perfectly with rails 3.1.3 in heroku.
Does your Gemfile.lock file mention this version of ActiveModel? Have you done a full bundle update rails / bundle install, then committed the file and re-deployed?
I had this same problem. What worked in development locally, did not work when I deployed to Heroku. It is likely that you have a gem that is locked to an older version of Rails (or ActiveSupport as was my case.) Review your Gemfile.lock file. You may will likely find a reference to an older version of a Rails component.
Should you find this to be true, try commenting out the gem and see if your app will run when you deploy to Heroku. If so, then review the GitHub forks of the offending gem to see if someone has a solution. If you find an alternative, specify the git repository in your gem file and then run bundle install.
e.g.
gem 'tinymce-rails', :git => 'git://github.com/spohlenz/tinymce-rails.git'

rails surveyor gem example gets sass syntax error

I'm installing the surveyor gem in a new (test) rails 3 project. I've run rails g surveyor:install, and rake db:migrate, and rake surveyor FILE=surveys/kitchen_sink_survey.rb
and then run rails server
It seems to "work" only the sass is not compiling correctly, so i get no styles and the page contains:
Syntax error: Invalid property: ":background-color= !background_color".
I'm running in Windows, with Ruby 1.9.2, the Gemfile contains
gem 'rails', '3.0.9'
gem 'sqlite3'
gem 'surveyor', :git => 'git://github.com/breakpointer/surveyor.git', :branch => 'rails3'
gem 'formtastic'
gem 'haml'
gem 'sass'
gem 'rake', '0.8.7'
Are you using the latest version of the gem? The breakpointer version is no longer the official branch. Check https://github.com/NUBIC/surveyor instead.