How do you convert a jruby-based application to ruby? - ruby

I made an application using jruby but I want to get it to work on a different computer which only has ruby installed.
It won't let me just change the gemfile from jruby to ruby, so how can I change it to run based on ruby?
This is my gemfile using jruby:
source 'https://rubygems.org'
ruby '2.2.2', :engine => 'jruby', :engine_version => '9.0.0.0'
gem 'cowsay'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use postgresql as the database for Active Record
gem 'activerecord-jdbcpostgresql-adapter'
gem 'rails_12factor', group: :production
# 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'
gem 'tzinfo-data', platforms: [:mingw, :mswin, :jruby]
gem 'puma'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]

change this:
ruby '2.2.2', :engine => 'jruby', :engine_version => '9.0.0.0'
to:
ruby '2.2.2'
and change:
gem 'activerecord-jdbcpostgresql-adapter'
to:
gem 'pg'
You probably need to update you database.yml also. You didn't paste it here, so I can't be sure. Just lookup the pg gem to see what you need to configure your conetions to.

no need to actually change much stuff as suggested in the other answer.
in the Gemfile specify platform qualifiers for MRI/JRuby specific gems :
# ruby '2.2.2', :engine => 'jruby', :engine_version => '9.0.0.0'
# ...
gem 'rails', '4.1.8'
# ...
gem 'activerecord-jdbcpostgresql-adapter', platform: :jruby
gem 'pg', platform: :mri
if you're not using anything AR-JDBC specific in database.yml (e.g. url: jdbc:postrgresql:...) than the same configuration with work on JRuby as well as C-Ruby

Related

Could not find Turbolinks

I have used the installer from rubyinstaller.org. But I get this error afterwards
Could not find gem 'turbolinks (~> 5) x86-mingw32' in any of the gem sources listed in your Gemfile.
I have tried some of the advices in the threats with a similar error, but no luck. Can someone guide in the right direction?
My gemfile:
source 'https://rubygems.org'
git_source(:github) do |repo_name| repo_name =
"#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git" end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.3'
# Use sqlite3 as the database for Active Record gem 'sqlite3', git: "https://github.com/larskanis/sqlite3-ruby", branch: "add-gemspec"
# Use Puma as the app server gem 'puma', '~> 3.7'
# Use SCSS for stylesheets gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported \runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' gem
'turbolinks-source', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# 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', platforms:
[:mri, :mingw, :x64_mingw] # Adds support for Capybara system
testing and selenium driver gem 'capybara', '~> 2.13' gem
'selenium-webdriver' end
group :development do # Access an IRB console on exception pages or
by using <%= console %> anywhere in the code. gem 'web-console', '>=
3.3.0' end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

bundle install error - Your bundle only supports platforms [] but your local platforms are ["ruby", "x86_64-linux"]

Getting this error doing a bundle install; google around seems like a common issue but I can't seem to find the fix (seem suggestion on Gemfile.lock but I moved that file to another directory)
# bundle install
Your bundle only supports platforms [] but your local platforms are ["ruby", "x86_64-linux"], and there's no compatible match between those two lists.
Here's my Gemfile and there is no Gemfile.lock in the directory.
[root#ip-172-30-4-16 rails]# gem -v
2.6.11
[root#ip-172-30-4-16 rails]# ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
[root#ip-172-30-4-16 rails]# bundle -v
Bundler version 1.14.6
[root#ip-172-30-4-16 rails]# cat Gemfile
source 'http://rubygems.org'
gem 'echoe'
gem 'rails', '~> 3.2.11'
gem 'mysql2'
gem 'prawn', '~> 0.5.0.1'
gem 'prawn-core', '~> 0.5.0.1', :require => 'prawn/core'
gem 'prawn-layout', '~> 0.2.0.1', :require => 'prawn/layout'
gem 'prawn-format', '~> 0.2.0.1', :require => 'prawn/format'
gem 'spreadsheet', '~> 0.6.5'
gem 'libxml-ruby', :require => 'libxml_ruby'
gem 'faker'
gem 'json'
gem 'rake'
gem 'jquery-rails'
gem 'therubyracer'
gem 'delayed_job_active_record'
gem 'daemons'
gem 'memcache-client'
gem 'rb-readline'
gem 'rubyzip', '~> 1.0.0'
gem 'zip-zip' # Rubyzip old API compatibility addon
# 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'
gem 'uglifier', '>= 1.0.3'
end
#group :development do
# gem 'ruby-debug19'
#end
group :test do
gem 'flexmock', '= 0.9.0'
gem 'machinist', '= 2.0'
gem 'test-unit', '~> 1.2.3'
# Use SimpleCov and Coveralls for test coverage reports
gem 'simplecov'
gem 'coveralls'
end
group :production do
gem 'passenger'
end
group :test, :development do
gem 'rspec-rails', '~> 2.0'
end
I had the same issue, I had to remove the .bundle directory and then bundle install worked.
I was able to work around issue /w bundle install --no-deployment option
If you get this error when using GitHub Actions, you can fix it by adding the Ruby platform to your Gemfile.lock:
$ bundle lock --add-platform ruby
Then commit, and push your change.

Configure Rails 4, MongoDB, Cucumber, Capybara

I am currently in the process of setting up my first Mongodb, Rails 4 environment and need to configure the gem before running bundle install. Here is my gem file.
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# User mongoid for database.
gem 'mongoid', github: 'mongoid/mongoid'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# 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', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :test do
gem 'cucumber-rails', :require => false
gem 'capybara'
#database_cleaner is not required, but highly recommended
gem 'database_cleaner'
end
It seems Mongo wont install as I cannot find the Mongo:Config file.
The config file is generated by running the following command:
rails g mongoid:config
Please read the mongoid documentation, it is quite good.

Gemfile when developing between two platforms

I am carrying out some development of a Ruby on Rails app between a Windows machine and linux machine. Not ideal but Ruby on Windows has improved a lot. Anyway i read that you can implement an IF statement so for example I have implemented this
source 'https://rubygems.org'
if RUBY_PLATFORM =~ /win32/
gem 'rails', '3.2.3'
gem 'sqlite3'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'nokogiri'
gem 'httparty'
gem 'devise'
else
gem 'rails', '3.2.3'
gem 'sqlite3', '1.3.6'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git'
gem 'less-rails'
gem 'uglifier', '>= 1.0.3'
gem 'execjs'
gem 'therubyracer', '0.10.2'
end
gem 'jquery-rails'
gem 'nokogiri'
gem 'httparty'
gem 'devise'
end
So this morning I merged my linux branch into the master branch (windows) and now i get the message
Could not find the less-rails in any of the sources
So it seems as if the IF statement has not worked or there is an issue with my bootstrap.css.less file in assets as I use this in my linux branch
How can i get this to work, so either have less working on both platforms or get windows to ignore the less gem
has anyone got around this before
UPDATE
Ok so i have found that if I specify
:platform => :ruby
after the less-rails gem it ignores it (though I had to add to execjs and rubyracer aswell) due to js runtime conflicts.. So question still remains as to what is wrong with my IF/ELSE statement
Thanks
Have you rebuilt the bundle lock file?
Try this on your Windows machine:
bundle install
bundle update
To learn about bundle, Gemfile, Gemfile.lock, and why you need to rebuild the lock when you switch platforms: http://gembundler.com/rationale.html

Rails Error: "Could not find gem 'activerecord-mysql2-adapter (>= 0) ruby' in the gems available on this machine

I did gem mysql2. This is how my GemFile looks like:
source 'https://rubygems.org'
gem 'rails', '3.2.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# 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'
gem 'mysql2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', :platform => :ruby
gem 'activerecord-mysql2-adapter'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
This is my configuration file:
development:
adapter: mysql2
encoding: utf8
database: qac_db
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Where am I going wrong?
Delete the line gem 'activerecord-mysql2-adapter'. Then run bundle install.
For what it's worth, I deleted my database.yml, and recreated it, then everything started working. No idea why, permissions problem perhaps?

Resources