I'm trying to figure out a way to distribute a Rails application in a fairly standalone way. Think of Sickbeard or CouchPotato, two apps you only need Python to run.
That's basically what I want to achieve, but with Rails instead. There are some failure stories out there and some that are just too complicated, but I'm hoping that there has been some advancements in the field that I just can't find.
Is there a way to distribute a Rails application including any gems it depends on in a way you only require Ruby installed to run it?
I have no intention of trying to obfuscate the source code.
Just use Bundler. Mostly every new Ruby installation have RubyGems and Bundler in standard so the only thing that End-User should do is:
$ bundle install
$ rails s
And will get running app with all dependencies installed.
Related
I have a rails application that I'm trying to use on other machines that do not have ruby, rails, or bundler installed. Is there a way I can zip up the rails application, the ruby environment and all its gems / dependencies? I'd like to be able to just send the zipped file to a computer without ruby and be able to run the application without having to install ruby, rails, bundler and all the gems in the rails app.
I've tried traveling-ruby, but it just packages ruby and not rails or bundler.
Edit: For clarification, the app is an internal tool for work. We would rather not deploy the app to a server, but rather just share the whole package with computers that may or may not have the dependencies installed.
You should consider Docker to prepare a "package" of self sufficient environment for your application. This way you will be able to send it to another machine and run without problems. You can use those containers for development purposes only. There is no requirement to deploy them into a server.
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've spent some time in web development and since I have decided that ruby is quite a nice language to code in I want to try the reason why some people say ruby got known : Rails
I installed rails in my linux machine however I am now trying to develop it in Windows. I know that it was recommended to install rails using RVM in linux however I'm not sure what is the best way to install it in Windows since I've read articles which said that
gem install rails
is a method which will cause you lots of bugs in both linux and windows
My question to you is what is a method which is "bugless" to install rails in windows?
Is
gem install rails
actually buggy?
Yeah, installing Rails on Windows is a little more complicated, but that's why they have bundles for it.
Go here and follow instructions.
http://railsinstaller.org/en
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