How to choose particular gem in Gemfile based on current RVM? - jruby

How can I conditionally choose which gem to use based on the Ruby VM currently in use?
Ideally I would like something like:
if [using jruby]
gem 'jruby-openssl'
This would only require the jruby-openssl if the RVM being used is JRuby.

Use the following in your Gemfile, as documented here: https://github.com/jruby/activerecord-jdbc-adapter
platforms :ruby do
gem 'sqlite3'
end
platforms :jruby do
gem 'jruby-openssl'
gem 'activerecord-jdbcsqlite3-adapter'
end

Attempting to answer my own question here.
We can do this using the following Gemfile directive:
if defined?(JRUBY_VERSION)
gem 'jdbc-sqlite3'
else
gem 'sqlite3'
end

Related

Error loading the 'mysql2' Active Record adapter

I am trying to upgrade my app and this is the error I am getting while deploying the app:
Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? can't activate mysql2 (< 0.6.0, >= 0.4.4), already activated mysql2-0.3.21. Make sure all dependencies are added to Gemfile.
here is my Gemfile:
https://github.com/BI-CTSICN/sparc-request/blob/master/Gemfile
gem 'mysql2', '~> 0.3.18'
gem 'rails', '~> 5.1', '>= 5.1.4'
I am using ruby 2.4.2
Your mysql2 version you use (0.3.21, checked in Gemfile.lock) is too old, required one is newer than 0.4.4.
Upgrade your mysql2 gem by changing version in Gemfile and running bundle update mysql2. Of course before that check what changed between versions and then run your tests to check if upgrade didn't break anything.
Just lock the mysql2 gem version not work for me. The only thing that work was match the rails gem version with mysql2 gem version, comparing both by it's release date.
Ex: I'm updating now my rails version from 5.1 to 5.2, so I want to put mysql 0.5.3 on my application (the most recent version). But I can put only the 0.4.10 version, because of it's release date match with rails 5.2.0.rc2 version that I installed right now (both are from march, 2018, with one day of difference).
I don't know why this working, but I guess that's a incompatibility problem between the rails and mysql2 versions that I tried to install.

Rails 4.1.6 Could not find generator bootstrap:install

I am getting the message Could not find generator bootstrap:install on Rails 4.1.6
My gem file looks like this:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails'
gem 'rails', '4.1.6'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails'
# 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'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster.
gem 'turbolinks'
# Build JSON APIs with ease.
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.
gem 'spring', group: :development
gem 'devise'
gem "therubyracer"
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
# twitter bootstrap css & javascript toolkit
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
# twitter bootstrap css & javascript toolkit
gem 'twitter-bootswatch-rails', '~> 3.2.0'
# twitter bootstrap helpers gem, e.g., alerts etc...
gem 'twitter-bootswatch-rails-helpers'
twitter-bootstrap-rails version is 3.2.0
therubyracer version is 0.12.1
execjs version is 2.2.2
When I run rails generate bootstrap:install less in command line, I get the above error. I do not understand what am I doing wrong.

Error compiling css file rails 4 [duplicate]

This question already has an answer here:
Sass and Compass weird css errors after install
(1 answer)
Closed 8 years ago.
I recently bought a new theme for my website, I wanted to include the new file in the application.css.sass:
#import "custom.css.sass"
And I get this error :
Invalid CSS after "#ffffff": expected expression (e.g. 1px, bold), was ";"
(in development/myapp/app/assets/stylesheets/application.css.sass:142)
The css file is working just fine in it's own with html file, what do I do?
Update
Some css arround 142 :
.notification_error,
.notification_ok {
background: #ffffff;
border:#e6e6e6 1px solid;
}
.notification_error:after,
.notification_ok:after {
background: #e6e6e6;
}
.shortcode_tab_item_title {
border:#e6e6e6 1px solid;
}
Also if I import :
#import "custom.css"
All works just fine, however if I use just .css my assets are not loaded on heroku.
UPDATE II: This is my Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
# Use postgres
gem 'pg', '0.12.2'
# soft deleted
gem "paranoia", "~> 2.0"
# 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
# background jobs
gem 'delayed_job_active_record'
# rack options
gem 'rack-rewrite'
# static pages
gem 'high_voltage', '~> 2.2.1'
#haml templates
gem 'haml-rails', '~> 0.4'
#youtube like ids
gem 'hashids'
#better form
gem 'simple_form'
#password digest stuff
gem 'bcrypt-ruby', '3.1.2', :require => 'bcrypt'
#aws stuff
gem 'aws-s3', :require => 'aws/s3'
gem 'aws-sdk'
gem 'fog'
gem 'carrierwave'
#assets
gem 'sprockets-rails', '~> 2.0.0', :require => 'sprockets/railtie'
gem 'asset_sync'
gem 'sass-rails', '~> 4.0.2'
gem 'compass-rails', '1.1.2'
gem 'coffee-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
group :development do
gem 'annotate'
gem 'quiet_assets'
gem 'foreman'
gem 'rails_best_practices', '~> 1.14.0'
gem 'better_errors'
gem 'binding_of_caller'
gem 'guard-livereload', require: false
gem 'pry-byebug'
gem 'spring'
end
group :development, :test do
gem 'rspec-rails', '~> 2.13.0'
gem 'guard-rspec', '2.5.3'
gem 'guard-spork', :github => 'guard/guard-spork'
gem 'spork', '0.9.2'
gem 'thin'
gem 'launchy'
gem 'awesome_print'
gem 'sql_queries_count'
gem 'debugger'
gem 'oink'
end
This is my Gemfile, in case I was doing something wrong here because some stuff is taken out of the rails 4
The file you're trying to import is css, not sass. So rename the file to custom.css.scss. Also, you don't have to write the file extension in the #import directive, so change it to #import "custom"; . Don't forget the semicolon at the end of the line, btw.
The issue is simply a difference between .scss and .sass syntax:
#scss
.notification_ok {
background: #ffffff;
border:#e6e6e6 1px solid;
}
#sass
.notification_ok
background: #fff
border: #e6e6e6 1px solid
As mentioned in another answer, just change the name from custom.css.sass to custom.css.scss
--
Further, you'll also want to just use the following:
#import "custom"

Warbler does not package Java/JRuby gems?

I have a Ruby on Rails app that I want to compile/package as a WAR file to host in Tomcat. I've added all of the relevant stuff I can find, but the WAR only appears to include the non-JRuby versions of gems. As a result, I get GemNotFound exceptions such as "could not find activerecord-jdbc-adapter" in Tomcat. If I open the WAR file in 7-zip, it does not show any of the JRuby or Java gems under /WEB-INF/gems/gems.
Warbler does not report any errors or warnings, and the WAR appears to contain everything it needs, except for these gems.
(Because this is a lightweight, internal app, I'm using sqlite for now... which explains the sqlite gems. The DB is stored outside the project and configured in the database.yml file.)
The relevant snippet from my Gemfile:
if defined?(JRUBY_VERSION)
gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
gem 'jruby-rack'
else
gem 'sqlite3'
end
I also tried explicitly including/excluding these gems in the warble.rb file:
config.gems -= ["sqlite3"]
config.gems += [
"jdbc-sqlite3",
"activerecord-jdbc-adapter",
"activerecord-jdbcsqlite3-adapter",
"jruby-openssl",
"jruby-rack",
"warbler"
]
As an interesting side note, if I modify my Gemfile to demand the JRuby gems, jruby -S bundle install works fine but warble gives a series of errors stating that the gems are only for use with JRuby. On the other hand, if I try to run it within JRuby (jruby -S warble) I get:
warble aborted!
no such file to load -- jruby_pageant
How can I convince Warbler that I want the JRuby gems?
Edit:
I also tried specifying platforms in the gemfile, as described in this blog post, but this causes warble to stack-overflow.
platforms :jruby do
gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter', :require => false
gem 'activerecord-jdbcsqlite3-adapter', :require => false
gem 'jruby-openssl'
gem 'jruby-rack'
end
platforms :ruby do
gem 'sqlite3'
end
Versions:
ruby 1.9.3
jruby 1.7.4
warbler 1.3.8
So it turns out that I was missing the jruby-pageant gem. Once I added this to the bundle, jruby -S warble produced the expected output.

Rails/MySQL: lazy symbol binding failed?

I am a .NET developer by day and an aspiring Rails developer at night. I am trying to use Rails and MySQL as my DB. I have successfully installed both. However, I am running into a really strange problem and really need some advice on how to get these two to work together. Here is the error message I get:
[rake --tasks] dyld: lazy symbol binding failed: Symbol not found: _mysql_get_client_info
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace
dyld: Symbol not found: _mysql_get_client_info
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle
Expected in: flat namespace
I have scoured the StackOverflow and have tried many things. I am sincerely hoping someone can help me. I have this all installed and running on a brand new MacBook Pro Retina. I am not terribly familiar with the underlying nuts and bolts of the OS in terms of the command line but can work my way around somewhat.
How do I get rid of this problem?
EDITED TO SHOW GEMFILE
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'json'
# 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 'therubyracer', :platforms => :ruby
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'