I'm still new to rails/ruby/bundler and am a little confused.
In our config/application.rb file there's this bundler segment:
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
and in our Gemfile we use different groups, e.g.
group :development, :test do
gem "rspec-rails", ">= 2.7.0", :group => [:development, :test]
gem 'shoulda-matchers'
gem 'watchr'
gem 'spork', '~> 1.0rc'
gem 'spectator'
gem 'debugger'
gem 'wirble'
end
But when I run RAILS_ENV=production bundle install (or bundle install --deployment), it still installs gems from the development/test group...
Why does this happens or how can I make this work properly?
THIS ANSWER IS OUTDATED
Take a look at --without option:
bundle install --without development test
By default Bundler installs all gems and your application uses the gems that it needs. Bundler itself knows nothing about Rails and the current environment.
An alternative solution is to use the bundle-only ruby gem. It can be used as follows:
> gem install bundle-only
> bundle-only production
This library does not pollute your bundler configs or augment Gemfile.lock; it is a simple alternative to the built in bundle --without every other group option that bundler provides.
Related
Gem files will remain installed in
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/sqlite3-1.4.0 for
inspection.
Results logged to
C:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/extensions/x86-mingw32/2.3.0/sqlite3-1.4.0/gem_make.out
An error occurred while installing sqlite3 (1.4.0), and Bundler cannot continue.
Make sure that gem install sqlite3 -v '1.4.0' succeeds before bundling.
I tried to install earlier version on sqlite, not working.
Tried one of the solutions from stackoverflow :
gem 'sqlite3', '~> 1.3.6'
getting this error
ERROR: While executing gem ... (Gem::CommandLineError)
Unknown command sqlite3,
Please help i'm new in Rails , this is my first project in rails.
Add gem 'sqlite3' to Gemfile in the root directory of your rails project. Then run bundle install and it should install sqlite and make it available to use in your rails project.
Specify git and branch for the gem sqlite3 in your Gemfile should fix the problem.
gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
For more info
https://medium.com/#declancronje/installing-and-troubleshooting-ruby-on-rails-sqlite3-windows-10-fix-87c8886d03b
cannot load such file — sqlite3/sqlite3_native (LoadError) Ruby on Rails
Replace gem 'sqlite3' with gem 'sqlite3', '~> 1.3.11' which is in Gemfile in the root directory of your rails project. Then run bundle install.
I have a sinatra server, and according to the gemfile, there are different groups of gems. Specifically, there is an application group, a testing group, and a development group. How do I switch my application between these three groups? Specifically, I want to be running my server in testing mode so I can do TDD.
Here is the gemfile.
source 'https://rubygems.org'
ruby '2.0.0'
gem 'sinatra'
gem 'sinatra-contrib', require: %w(sinatra/config_file)
gem 'thin'
gem 'slim'
gem 'sinatra-assetpack'
gem 'zurb-foundation'
gem 'compass'
group :application do
# Here should be all the specifics for the application
end
group :test do
gem 'rspec'
gem 'coveralls'
gem 'capybara'
gem 'rubocop'
end
group :development do
gem 'rake'
gem 'guard', '2.2.3'
gem 'guard-rspec'
gem 'guard-rubocop'
gem 'guard-livereload'
gem 'guard-shotgun', git: 'git#github.com:rchampourlier/guard-shotgun.git', branch: 'master'
gem 'blam'
end
Gem Groups
Bundler installs by default everything. What you probably want is something like this:
$ bundle install --without test development
for your productive server, this install everything except the test & development group.
source: http://bundler.io/v1.3/groups.html
Sinatra Environment
Since you mentions sinatra explicit you maybe also interested in the sinatra config blocks
# run only in development environment
configure :development do
use Rack::Session::Pool, :key => '', :expire_after => 60 * 10
end
# run only in test environment
configure :test do
use Rack::Session::Pool, :key => 'session', :expire_after => 60 * 60
end
# run everytime
configure do
MongoMapper.database = 'food'
User.ensure_index(:username)
Product.ensure_index(:rnd)
end
You can set the different environments with RACK_ENV.
example:
RACK_ENV=test ruby mytest.rb
source: http://www.sinatrarb.com/configuration.html#built-in-settings
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.
When i push my app to heroku it gives me following error
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.3.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
You have added to the Gemfile:
* therubyracer
!
! Failed to install gems via Bundler.
!
! Heroku push rejected, failed to compile Ruby/Rails app
I deleted my Gemlock file and again bundle install it but still gives me same error. I also tried bundle install --without development:test for production it also gives me same error What can I do. Here is my Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.9'
gem 'carrierwave'
gem 'newrelic_rpm'
#gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
#gem "twitter-bootstrap-rails"
gem 'will_paginate', '3.0.3'
#gem 'bootstrap-will_paginate', '0.0.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'mysql2'
gem 'dynamic_form'
gem 'therubyracer', '0.10.2', :platforms => :ruby
gem 'devise'
gem 'hirb'
# Gems used for Facebook
gem 'facebook_oauth'
gem 'oauth','0.4.7'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'thin'
gem 'pg'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
#gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
Try run bundle install than push changes to remote repo.
Also if you use therubyracer for assets compilation, you may precompile assets locally and read this docs:
https://devcenter.heroku.com/articles/rails-asset-pipeline#compiling-assets-locally
https://devcenter.heroku.com/articles/rails-asset-pipeline#therubyracer
therubyracer gem is used to evaluate JavaScript from within Ruby(It embeds the JavaScript interpreter into Ruby).
This gem is required, if you are developing in Ubuntu since, ubuntu doesn't have a Javascript runtime.
But its not case with Heroku.
So, just keep the line for therubyracer gem in the Gemfile under development group like shown below :
group :development do
gem 'therubyracer', '0.10.2', :platforms => :ruby
end
According to Heroku docs:
If you were previously using therubyracer or therubyracer-heroku, these gems are no longer required and strongly discouraged as these gems use a very large amount of memory.
As a replacement on Ubuntu you can install NodeJS:
sudo apt-get install nodejs
I took a look about this problem within the list of question but nothing helped.
This is my first question in stackoverflow so please accept my apologies in case I do something wrong. Also I still have a lot of english to improve.
I'm installing Spree following the github instructions
$ gem install spree
$ rails new my_store
$ spree install my_store
when I get this message
...
Admin Password [spree123]
gemfile spree
gemfile spree_usa_epay
gemfile spree_skrill
run bundle install from "./my_store"
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
precompiling assets
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
...
Well, as the guide suggests, in case of circular dependency issues do:
$ gem install spree_cmd
$spree install my_store -A
gemfile spree
gemfile spree_usa_epay
gemfile spree_skrill
run bundle install from "./my_store"
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
precompiling assets
git://github.com/spree/spree_usa_epay.git (at 0cb57b4) is not checked out. Please run `bundle install`
I changed directory to the app and run the command:
$cd my_store
$bundle install
and I get the following error
Bundler could not find compatible versions for gem "rails":
In Gemfile:
spree_usa_epay (>= 0) ruby depends on
rails (<= 3.1.3, >= 3.1.1) ruby
rails (3.2.1)
after this I changed the gem file to work with rails 3.1.3 and coffeescript gems and repeat the whole process again and I get this.
Users/Snake/.rvm/gems/ruby-1.9.3-p0/gems/activerecord- 3.1.3/lib/active_record/base.rb:1088:in `method_missing': undefined method `mass_assignment_sanitizer=' for ActiveRecord::Base:Class (NoMethodError)
from /Users/Snake/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.1.3/lib/active_record/railtie.rb:59:in `block (3 levels) in <class:Railtie>'
It think it might be something with version of rails a spree but I don't know were to start.
Does anybody had this issue before?
I running Mac OS X 10.5.8
rails 3.2.1
ruby 1.9.3p0 (2011-10-30 revision 33570) [i386-darwin9.8.0]
ImageMagick #6.7.4-6_0+q16
As #Anatoly Ruchka suggested the problem was using rails 3.2.1, so I switched to 3.1.3.
This is what I did, I found a post of #vonconrad where he explain how to create a rail project without touch the installation.
1) I create a directory folder for my project:
$mkdir old_rails313
$cd old_rails313
$touch gemfile
$nano gemfile
2)
I pasted a gemfile definition specifying as you mention the version of rails I want, so it looks like this
source 'http://rubygems.org'
gem 'rails', '3.1.3'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.1.5'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem "rspec-rails", ">= 2.8.0.rc1", :group => [:development, :test]
gem "factory_girl_rails", ">= 1.4.0", :group => :test
gem "cucumber-rails", ">= 1.2.0", :group => :test
gem "capybara", ">= 1.1.2", :group => :test
gem "database_cleaner", ">= 0.7.0", :group => :test
gem "launchy", ">= 2.0.5", :group => :test
#gem "devise", ">= 1.5.0"
gem 'spree','1.0.0'
3) then I run
bundle install
bundle exec rails new .
rails g spree:install
rails s
After installing I've got a conflict with the gem 'spree','1.0.0', so I comment it out.
Also I've got a warning but it works:
[DEPRECATION WARNING] Nested I18n namespace lookup under "activerecord.attributes.spree/order" is no longer supported
Thanks a lot
I think you should use rails version 3.1.3 for spree_usa_epay
TO do that you should uninstall all rails what you have on machine
to watch use
gem list -d rails
than
sudo gem uninstall rails -v ...
and create new project with
rails new my_store
than edit Gemfile and paste
gem 'spree', '1.0.0'
and
bundle install
well done
rails server