What do I need to modify to change my ordinary Ruby on Rails project into a JRuby on Rails project? In addition, is it likely that a gem I included in my RoR project will be broken in the JRuby version of my project?
Lastly is there any way to create a JRuby on Rails app in APTANA or any other editor?
You will need to switch to Jruby instead of Ruby and this could be done using RVM. (www.beginrescueend.com)
You will have problems with gem compatibility when you switch to jruby not all gems will work. Usually gems with C extensions.
Lastly, for an IDE I am sure aptana is fine. You are still writing ruby code. Just when you run your code you will be using the JVM.
The main advantage of jruby instead of normal ruby is we can call the java libraries. And if you want you can even use Hibernate.
And switching if you are on a windows machine you need to use PIK(RVM for windows).
Like ericraio said there may be some gem dependency but most of the time the bundler will take care of that, so you don't need to worry about things(Most of the time).
If you want to check a particular gem please visit this site http://rubygems.org/
For my development I'm using NetBeans 6.9.1. If you want any help regarding how to make you first program in netbeans I'm ready to help.
I prefer to use command prompt to create and run rails project
Related
Given we use a preferred flavour of a ruby version manager (RVM or Rbenv) the ruby gems are isolated per ruby version.
Let's say we want to work on multiple applications locally (they are completely separate applications) and we want to use the same ruby version and the same rails version how do we properly isolate them and their gems? Are gemsets the (only) answer here? I mean if I have 5 applications with the same ruby version and I keep adding gems on all 5 fronts it's just a matter of time when one of the applications is ok with the latest stable gem version while one of the apps will still need to roll on an older version of the same gem due to legacy dependency or whatnot. How do you guys avoid this timebomb?
What if we want to use the same ruby version on multiple apps but a different Rails version? Rails being 'just a gem' is the answer same as for the above?
Thanks.
I'd recommend to use:
rbenv to handle multiple ruby versions on the same machine
bundler to define the dependencies of each application
Make sure to push .ruby_version, Gemfile and Gemfile.lock to make sure every is using the appropriate version of each gem...
So someone at my work created a web application in JRuby a while ago, and I'm tasked with...
Understanding the code
Running the JRuby web application locally
Determining whether to fix it up or rewrite it, add functionality, etc.
I'm completely new to JRuby and am kind of struggling with the basics. I'm staring at the code I pulled, containing the folders app, bin, config, lib, script, test, etc. and also containing a Gemfile, Gemfile.lock, a Rakefile, etc. I have no clue how to run this thing locally...
From what I can tell so far, there are a few interacting systems here. They are: JRuby, Ruby, Java, Rails, Gem, Rake, and Bundler. What I am struggling with is how they all work together.
JRuby - My understanding is that, with JRuby, you develop with the Ruby programming language, and it uses the Java Virtual Machine because of whatever benefits therein that I'm unaware of.
Ruby - Ruby has a framework specifically for building web applications, called Rails, which utilizes an MVC framework for ease in creating web applications. JRuby can work off of straight Ruby or Rails.
Rake - I'm not too sure what Rake is. I think it's basically Make. You call rake on a Rakefile and it can perform whatever tasks you specify.
Gem - I think gems are a way of packaging Ruby web applications (rake and bundler are gems?). I'm pretty baffled by this point. I think gem is a command line tool to package a Ruby web application, at which point you refer to it as a "gem."
Bundler - Very lost by this point. I think you define a Gemfile (unsure how Gemfile.lock is used), and use bundler to bundle all of the gems from this Gemfile together. Then you can just include all of these in your app with "require 'bundler/setup'"... although I think you have to require any gems that you defined in your Gemfile again in the app anyways?
JRuby - MRI Ruby (or C Ruby) is the original implementation of the Ruby language. MRI Ruby was written in C. JRuby is the implementation of Ruby on top of the Java Virtual Machine, and a lot of it is written in Java. I'm fuzzy on a lot of the finer details between JRuby and MRI Ruby, but here's what I know based off of what I've learned using JRuby:
JRuby is faster because it's multi-threaded. This means that it can manage multiple requests at once. MRI is not multi-threaded. Therefore, you'll see a lot of benchmarks between JRuby and Ruby, and you'll see that JRuby outperforms Ruby in terms of speed.
JRuby doesn't have as good gem support. This means that you'll be missing out on a lot of gems.
JRuby only recently got Ruby 2.2 compatibility with the release of JRuby 9.0.0.0. However, there's still a lot of kinks to be worked out with the latest version of Rails, so I would do a lot of research into making sure that there aren't major issues between JRuby 9.0.0.0 and Rails 4.2+.
Rake - you've essentially got this correct.
Gem - They're essentially packages of code you can integrate into your projects and run. This is probably the neatest feature of Ruby. Say you want to use the RSpec testing framework. It's super easy to get running if you include that in your project's Gemfile.
Bundler - Gemfiles are exclusive to Bundler. I like to think of Bundler as a dependency manager for your gems. You can specify what versions of each gem will run in your Gemfile, and when you run a bundle install, Bunder will pull and install the specific versions of each of the gems for you. Each bundle install or bundle update will update your Gemfile.lock, which lists out the versions that your project's gems are "locked" to. Gemfiles are exclusive to Bundler, so you'll also see things like .gemspecs floating around in other Rails engines or Rails apps that you may work on.
I'm learning Ruby on Rails with the AWDR book and have had to be specific about which version of Rails and Ruby that I am running on my local machine. I have just discovered that I need to roll back from ruby 1.8.7 to ruby 1.8.6 here. I also needed to roll back Rails to support the scaffold method so I could start the tutorial easily.
My question is: When I start contracting, developing and deploying projects in the real world, how am I going to manage all these different versions?
It looks to me like Rail's low tolerance for legacy code negates its ease of use philosophy! But I'm sure I'll grow to appreciate RoR.
As for Rails, What you can do is freezing your version, for example:
Make sure to install the proper Rails version, suppose you want version 2.2.2 : gem install rails v=2.2.2
Freeze and pack Rails with the project itself : rake rails:freeze:edge RELEASE=2.2.2
Now you will find Rails packed inside the vendor folder of your project, so you don't have to install Rails on the deploying machine.
And for Ruby, I like Ruby Version Manager(RVM), the easiest way to manage Ruby versions.
RubyGems is Ruby's package manager. You can install as many versions of gems (packages) as you want. You can install the latest by running sudo gem install rails (at the moment it will install 2.3.5). If you need 2.2.2, specify that with the -v or --version option: sudo gem install rails --version 2.2.2. Rails also installs a binary (yes, I know it's not really a binary file), rails, which generates a project. Because you have several versions of the gem, you need to control which binary gets called. When you install the rails gem, RubyGems puts a file in it's bin/ dir, which is a "link" to the real rails binary. That is the one you "call" when you say rails on the command line. However, all of the rubygems "link" binaries accept a parameter of it's own, which is what version you want to use. You would use the 2.2.2 rails binary like this:
rails _2.2.2_ my_project
I think the default is to use the most recent version, so if you want to use the most recent version, do this:
rails myproject
However, I see that you use 2.2.2 to get access to the scaffold method. I would strongly suggest you not to use that method, there's a reason for removing it. The scaffold method hides code, and makes customization hard. Instead, use the scaffold generator:
./script/generate scaffold --help
Good luck on your future rails adventures!
The latest version of Agile Web is written for 2.2.2 I believe. For this basic app they walk you through I'm very certain it should work with 2.3.x
The answer to the question for how you keep up is that you update your apps as needed and read the api and Changleogs to find out what has changed and fix the stuff that upgrades break. A great way to help with this is having a good test suite with good test coverage.
I have an older Rails app that I need to run. But I have the latest version of Rails.
When I try to run this older app it says:
Missing the Rails 1.99.0 gem. Please
gem install -v=1.99.0 rails
But when I run the command: gem install -v=1.99.0 rails
ERROR: could not find gem rails
locally or in a repository
Not sure what to do next. Could someone help me understand what's happening here?
And my second question, related to this problem is: It seems silly that I need to revert to an older version of Rails just to run this one legacy app - there must be a better way of doing this?
AFAIK, v1.99.0 is sort of a v2.0 prerelease, so you could try installing v2.0.x, changing the RAILS_GEM_VERSION in config/environment.rb and runing rake rails:update.
If you think about it, it's not as silly as it might seem at first. You make an app using a fast evolving web framework as RoR. Your choices are: continue developing your app at aproximately the same pace the framework is evolving, or freeze the rails gem (and evertything else your app depends on, like gems, plugins) into your app in order to make it less fragile to expecting gem updates.
Regarding the second question: yes it is silly. Fortunately the Rails team spotted that silliness and at some point they gave us the ability to "freeze" the versions of Rails libraries required by an application (and also specific gem versions) into the vendor directory.
To freeze your version of Rails:
rake rails:freeze:gems
There's a good blog post from a while back describing this.
Unless you install and deploy RVM, your installation will roll back your system rails installation, which will impact your other projects. If you want to manually administrate your development environment this way, you can uninstall rails first, and then install the desired version of rails for the current project.
But try to install your rails gem instead with this syntax:
sudo gem install rails -v 1.99.0
I'm new to Rails development, and I'm trying to figure out how to use an older version of Rails with Apatana's RadRails IDE. I'm trying to help out a friend who has a site built on older version than the one that automatically gets downloaded by RadRails, and I'm pretty sure the two versions wouldn't be compatible (the site is using some pre 2.0 version, not sure of the exact number offhand).
Is there a way to tell RadRails to get and use a specific version of Rails? Or is there something I can do at the command line to change the installed version of Rails? I'm only vaguely familiar with the "gem" package system, but I'm assuming it would involve that.
Any help would be much appreciated!
Use the Rake task rails:freeze:gems in your rails project and give it the version you want to use. For example:
rake rails:freeze:gems VERSION=2.1.0
That will put the right version of Rails into vendor/rails, which is loaded by default if it exists.
If you don't want to freeze the gem into your project (using rake rails:freeze:gems), you can install the rails gem of the version you want to use:
gem install rails -v 2.0.2
and then specify the rails gem to use in your config/environment.rb:
RAILS_GEM_VERSION = '2.0.2'