Rails 3.1 Deployment to Heroku Error - ruby-on-rails

I'm trying to deploy my app to Heroku, I've done this before on my Windows machine, and now I am currently using a mac.
I'm trying to use Postgresql for the first time.
I have the following in my Gemfile:
gem 'pg'
EDIT:
AndrewDavis-OSX:lunchbox ardavis$ rvm list
rvm rubies
=> ruby-1.9.2-p180 [ x86_64 ]
AndrewDavis-OSX:lunchbox ardavis$ heroku rake db:migrate
rake aborted!
/app/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end
App::Application.config.session_store :cookie_store, key: '_app_session'
^
(See full trace by running task with --trace)
(in /app)
As you can see, I am running ruby 1.9.2. And there is the error for my heroku migration.
EDIT 2:
Just created a brand new rails app using Rails 3.1.rc1. I set the gemfile to include
group :production do
gem 'therubyracer-heroku', '0.8.1.pre3'
gem 'pg'
end
I did a quick git init, commited, then 'heroku create' and 'git push heroku master'. Those all work just fine. However the problem is when I try 'heroku rake db:migrate'. I get the same error that you see above.
TEMP FIX EDIT:
So... if I change my config/initializers/session_store.rb from
App::Application.config.session_store :cookie_store, key: '_app_session'
to
App::Application.config.session_store :cookie_store, :key => '_app_session'
and change my config/initializers/wrap_parameters.rb from
ActionController::Base.wrap_parameters format: [:json]
to
ActionController::Base.wrap_parameters :format => [:json]
Then I'm able to do 'heroku rake db:migrate' just fine. Anyone care to explain why this works locally the original way, without any modification of the colons/hashes? The original way is the generated default from doing 'rails new myApp'

The Heroku stack needs to be migrated, you can run this command to do so:
heroku stack:migrate bamboo-mri-1.9.2
I was running 1.9.2 locally, which is why it was working locally. But on Heroku, it was running 1.8.7.

The problem is that there is a new-style hash argument available in Ruby 1.9.2 but unavailable in Ruby 1.8.7 which is:
key: value # only available in 1.9.2 but
:key => value # available in 1.8.7 and 1.9.2

This is just an additional pointer to some. If ever you are getting the same error in your development environment, on an app that was functioning just fine moments ago, check your ruby version as Preksha/Alex Kliuchnikau mentioned above.
$ ruby -v
If ruby is not set to 1.9.2 or above, you can do that with rvm
$ rvm --default 1.9.2 (1.9.3 is what I currently use)
If it's not responding to rvm command, add rvm to your bashrc file by copying the following line in your terminal:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" ' >> ~/.bash_profile

Related

Capistrano/rails doesn't work with rvm

I am trying to deploy Rails app with capistrano. It's Rails 5.1 based.
Ruby version is managed by rvm.
I am using ruby 2.2.3, created gemset manually.
Here is deploy.rb
set :rvm_type, :user
set :rvm_ruby_version, '2.2.3#cardlove-api'
...
with RAILS_ENV: fetch(:environment) do
execute :rake, "webpacker:install"
end
So, it seems worked when Rails < 5.0. But when Rails > 5.0, webpack should be installed by this command:
bundle exec rails webpacker:install
(instead of bundle rake)
with RAILS_ENV: fetch(:environment) do
execute :rails, "webpacker:install"
end
But it doesn't work for me. I've installed bundle in the gemset I am using, but getting error:
01 bundle exec rails webpacker:install
01 bash: bundle: command not found
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user#IP: rails
exit status: 127
rails stdout: Nothing written
rails stderr: bash: bundle: command not found
Of course, I included capistrano/rails in my capfile.
capistrano/rvm
capistrano/rails
I am not sure why I am getting error. I think I configured correctly , but...
Anyway, Would you like to help me to fix this issue?
You can use capistrano/bundler

"Missing these required gems" on specific server, gems are installed

Trying to run rake db:migrate I get:
$ rake db:migrate
(in /home/user/domains/staging)
log level debug
Missing these required gems:
haml ~> 3.1.4
htmlentities
fastercsv
You're running:
ruby 1.8.7.72 at /usr/bin/ruby1.8
rubygems 1.3.7 at /home/user/.gem/ruby/1.8, /usr/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
rake aborted!
no such file to load -- json
I have two servers en both are updated via a git repository. On one server everything works fine, on the other I get the above error.
Whats up?
Have you tried bundle install or sudo bundle install in production? You might also try bundle exec rake db:migrate instead of just rake db:migrate. These are kind of guesses, but might help.
Is the path to the "ruby"/"rake" etc executables pointing at the correct one on the server that isn't working? It looks like you want to use REE, but your stack trace is 1.8, not REE.
You may need to export an environment variable to update your path to point at the correct Ruby binaries.

Deploying Chiliproject to Dreamhost

Having some issues deploying this. I've tried to deploy it twice now. Here's what I've done so far....
Installed the gems and versions required on the install page:
gem install -v=2.3.5 rails
gem install -v=1.0.1 rack
gem install -v=0.8.7 rake
gem install -v=0.4.2 i18n
Downloaded the package:
git clone git://github.com/chiliproject/chiliproject.git
cd chiliproject
git checkout stable
Had to find and set bundle since it wasn't in my path:
BUNDLE="/usr/lib/ruby/gems/1.8/bin/bundle"
Put my database info into database.yml:
And then started the bundle stuff:
$BUNDLE install --without=postgres rmagick
$BUNDLE exec rake generate_session_store
The last command got the error:
rake aborted!
can't activate rails (= 2.3.5, runtime), already activated rails-2.3.12. Make sure all dependencies are added to Gemfile.
So I changed 2.3.12 to 2.3.5 in the Gemfile and carried on:
RAIL_ENV=production $BUNDLE exec rake db:migrate
Then I got an error on this command too:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `autoload_paths' for #<Rails::Configuration:0x68a68dbb82c0>
/home/USERNAME/DOMAIN/public/config/environment.rb:44
I tried commenting out line 44 there, but then it threw another error undefined methodconvert_to_without_fallback_on_iso_8859_1' for class Class' so I didn't want to play around with it further. Note this only happened the second time I tried to deploy it. The first time I tried db:migrate succeeded (and I checked there was not data already in the DB).
*So for the second try I am stuck here :-( *
But this is what happened the first time after db:migrate succeded....
RAILS_ENV=production $BUNDLE exec rake redmine:load_default_data
With the last command however it failed saying permission denied for mysql 'user'#'173.236.128.0/255.255.128.0' and I was like WTF is it trying to connect to a network as if it were a host?
So I moved on, copied my configuration file and environment files in. Changed/added these lines:
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5'# unless defined? RAILS_GEM_VERSION
if ENV['RAILS_ENV'] == 'production' # don't bother on dev
ENV['GEM_PATH'] = '/home/USERNAME/.gems' + ':/usr/lib/ruby/gems/1.8'
end
Then made this stuff writable and restarted Passenger:
chmod -R 777 files log tmp public/plugin_assets/
touch tmp/restart.txt
Sorry for the wall of text, is anybody able to shine some light on something I've done wrong?
Thanks in advance.
EDIT: So this is all wrong, here's how I got it working
rm ~/.gem*
gem install bundler
PATH=$PATH:/usr/lib/ruby/gems/1.8/bin
cd ~
git clone git://github.com/chiliproject/chiliproject.git
cd chiliproject
git checkout stable
cp * ../example.com/ -R
cd ../example.com
# Make sure database is working
bundle install --without postgres rmagick test
bundle exec rake generate_session_store
RAILS_ENV=production bundle exec rake db:migrate
# No output is no good, check database.yml
RAILS_ENV=production bundle exec rake redmine:load_default_data
Or see this: https://gist.github.com/1127306
The current ChiliProject stable releases (2.x) require the use of bundler. Thus the answer by Slotos is incorrect here. gen install doesn't work anymore, we NEED bundler.
Also, we require Rails 2.3.12 now. You won't get any working results if you arbitrarily edit files. On certain platforms, you need to adapt the Gemfile (e.g. when using Ruby 1.8.6 or for certain versions of ImageMagick). For the currently suggested setup using Ruby 1.8.7 or REE, you don't need to adapt anything though.
For installing the dependencies of the currently stable ChiliProject 2.x releases, you basically need to do the following:
At first you need to make sure that the directory where gem binaries re installed to is in your $PATH. This can be temporarily be achieved by running this (in your case)
export PATH=/usr/lib/ruby/gems/1.8/bin:$PATH
Then you need to install the bundler gem and instruct it to install all dependencies
gem install bundler
bundle install --without rmagick postgres test # in your case
What is really strange in your case is that rake seems to try to enable Rails 2.3.5. It should not do that (and doesn't unless you have changed certain files). I strongly recommend to start with a new clean source tree and don't change any arbitrary files.
Don't mix up gem install commands with bundler package management. You will get unexpected results from doing so.
If you really want to use bundler - add all the gems you want into a Gemfile.
Otherwise just omit it.
Quick search for "bundler chiliproject" lead me to chiliproject-gemfile. Apparently it have been merged into unstable already.

how to deploy "surveyor" Rails plugin on heroku.com?

I'm kinda new to this stuff, and I need some help please
I created my rails app using ruby 1.8.7/rails 2.3.8
I added Surveyor to the Gemfile.
I pushed the project to heroku.com using git, went through the normal
procedure in the "Quick Start" guide on heroku, including
$ heroku bundle install
$ heroku db:migrate
and all went through peacefully. But when I try to create a survey
using:
$ heroku rake surveyor FILE=surveys/kitchen_sink_survey.rb
I get the following error:
rake aborted!
uninitialized constant Surveyor
Can anyone help me with this please?
You will need to run rails generate surveyor:install before db:migrate
You need to also add the gem to your environment.rb
Rails::Initializer.run do |config|
config.gem "surveyor"
end

Ruby Rails Gems question

I'm trying to install a Jabber Client called PSI on Linux Redmine installation.
So, I have done the following:
$ gem install xmpp4r
$ cd {REDMINE_ROOT}
$ git clone git://github.com/mszczytowski/redmine_messenger.git vendor/plugins/redmine_messenger
$ vim config/messenger.yml #( <- Haven't set this up yet.)
$ rake db:migrate_plugins
When I do the rake it tells me:
-bash-3.2$ rake db:migrate_plugins
(in /home/username/redmine)
rake aborted!
no such file to load -- xmpp4r
The gems seem to install properly and everything. Just not sure why it's not working.
maybe you have to mention it in config/environment.rb:
config.gem "xmpp4r"

Resources