Developing a Rails app in Netbeans/JRuby but deploying to Ruby (C) - ruby-on-rails

I'm using Netbeans and JRuby to develop a Rails web application.
But for deployment, I will be using Heroku.
Since Heroku uses the Ruby-C implementation, I was wondering my use of JRuby can cause problems? Is this approach a safe thing to do?

You can develop in NetBeans and use C-Ruby (aka MRI Ruby). Just install Ruby separately, go to Ruby Platforms, and select it. I highly recommend you install a separate Ruby anyway, whether or not it is MRI Ruby, because if you use the built-in NetBeans version of JRuby (which is often not the latest) and then upgrade NetBeans, you'll lose all the gems you've installed. Installing Ruby/JRuby outside of NetBeans helps you to better manage the versions and gems.
Now to answer your questions: Likely you will not encounter problems with basic Rails applications. If you ever have the need to use non-native libraries you may run into issues. Some gems (e.g. Nokogiri) have a C version and a Java version so you'd be OK, but if you wanted to use a plugin that relied on RMagick, for example, you'd struggle, as you'd probably go a different route if you were developing and deploying with JRuby.
Bottom line: I wouldn't recommend it. I'd recommend using the same platform for both. But you can use MRI Ruby in NetBeans.

funny thing: I stumbled in your question while looking for a tool chain to do it the other way round (developing in MRI Ruby, deploying with JRuby). Of course you can not use any Java classes and internals, but this for sure is obvious to you. According to my results thus far you shouldn't encounter any process structural issues, because MRI Ruby adheres to the shared nothing principle whereas your requests in the development app share the VM at least. Maybe to be shure you should hae a look at http://kenai.com/projects/jruby/pages/DifferencesBetweenMriAndJruby and read it in a reverse sense, especially the "Native Endian is Big Endian" paragraph when un-/packing Strings or Arrays.

You will save yourself a lot of trouble if you develop on the same platform as you deploy. This goes for OS as well, especially Windows then deploying on Linux, less so with OSX, but still sometimes an issue. You will be troubleshooting on your deployment system and that just isn't the same as catching something as you code it in development. I recently started using JRuby for a project and there are quite a few differences and different gems altogether in some cases.
As for loosing installed gems etc. take a look at using Bundle while you are at it, that will also save you some trouble down the line with gem versions out of sync.

Related

Uninstalling Ruby to go to an older version

I'm trying to learn Ruby On Rails, and found I can't really use Ruby 2.2.2 because Nokogiri doesn't support it on Windows yet.
How do I roll back Ruby to an older version so I can develop on an older framework while I wait for Nokogiri to come up with a product for Windows and Ruby 2.2.2?
What is the best way to uninstall it so I don't have bits hanging around that might cause issues?
This is in response to my question: "Error installing "nokogiri" in a Ruby on Rails application?"
Linux users: please remember that not everyone is interested in switching their OS, running 2 machines, trying to figure out dual boot, or dealing with virtual machines dragging down a host. While Linux is a great environment for software development, people, like the OP, just looking to try their hand at something (like ruby/rails) should not immediately be told to switch to something completely unfamiliar which might not even adequately support their normal day to day activities.
Since I am not a believer in making anyone leave an environment they are comfortable with (especially since you stated "learning". Why would you want to make an additional investment just to try something out?) and because I did not want my comment to get over looked as it will help with your issue, I have decided to post this as an "answer".
Mac and Other *nix based OS's have the ability to install rvm (Yes I know there are more but rvm is my personal choice and a community favorite) which allows you to manage different versions of ruby on the same OS.
While rvm is not available for Windows there is a small application called uru which will get you as close from a windows standpoint.
Installing a version manager means that you do not need to uninstall or rollback anything you can simply install a new/old ruby version side by side the current versions you have and switch between them fairly easily from command line.
While uru does not have all the fancy features that other applications like rvm possess (by design). It contains the important ones (primarily in your case switching ruby versions). The CLI is very simple and straight forward. Examples of uru Usage
Also: Please note I work in an Windows centric Office and have developed more than a few fully functional rails applications on a windows machine. Yes there are some headaches when dealing with native extensions and know that you will always be slightly behind the leading edge for ruby and rails but it is completely possible and feasible to build enterprise level web applications completely in a Windows environment without ever installing Linux at all. (Note I do use dedicated Linux machines for non development web servers)
Go to your control panel and find the ruby or rails installer. Uninstall it. Go to your file explorer and make sure the folder is gone.
Now go to http://rubyinstaller.org/downloads/ and pick an older version. Follow that process just like the first time you installed ruby. Then go get nokogiri and whatever other gems you like and enjoy.
I had the exact same issue when trying to some gems(stanford core nlp & treat) to work that relied on JVM that was 32bit instead of 64 like the version of ruby I was running so I reverted to 1.9.3.
I'm also in the avoiding moving to OSX or linux camp so I feel your pain man.
Let me know if this works and good luck!

Rails/Ruby pain - How to check if gem is UNIX/UNIX-like based?

Is there any way to see if a gem is only supported on UNIX/UNIX-like systems?
Are there any gem that can "screen" all gems and see if there is any trouble using it with Windows.
Short answer: No.
To be honest, Windows is a second-class citizen in the Ruby world. Mostly this is because where Linux, BSD, OS X, and virtually every other POSIX-based system will agree on one thing, Windows will go and do something completely different.
Even a gem that's intended to work with Windows may break occasionally due to an oversight of the developer. Most gem authors do not have a continuous integration server that runs against Windows and depend on bug reports from users.
Supporting Windows is difficult not only because of API differences, but because of the nature of the Windows ecosystem where access to a command-line compiler is not to be taken for granted like it is on other systems. This means any gem that's not pure Ruby can be a challenge to install, especially if it has other dependencies that are tricky to get working in Windows.
The only way to know for sure is to try and install the gems and see if they work.

Just starting in Rails --> Is it really buggy these days or is it just me?

I've spent a fair bit of time with PHP & Python frameworks and recently thought I'd branch out to rails. The framework itself I like, but I seem to spend at least half my development time navigating through odd bugs and/or version incompatibilities between rails/ruby/rake/gems.
I'm happy to battle through it all if it gets less of a hassle, but even after a month it seems like I spend 90% of my time chasing down other people's bugs & only 10% of my time chasing down my own. The only guy I've talked to (who used it extensively until 2008) suggests "For the past 2 years, that's pretty much rails"
Any opinion on this? Does it get better, or is this just par for rails development at the moment?
Running it through Ubuntu 10.04, if it matters.
Rails is in transition right now between 2.3x and 3.0 so you are going to find it quite challenging as much of the most recent documentation and rails plugin readmes are being updated for rails 3. There are several tools that are indispensable right now for negotiating this stuff. First, Rails 3 uses bundler to manage dependencies, it is a much more civil way to manage gems.
gem install bundler
cd my_rails_project
bundle install
RVM (ruby version manager) is awesome and I would recommend installing it. Then you can build gemsets and dependency sets on a per project basis. and you don't need to superuser access to install.
also, if it were me, I'd just go ahead and start in rails 3
gem install rails --pre
if you want to stay with rails 2.3.x use the rake task for installing declared dependencies.
rake gems:install
if the project is a good project, it will be pretty specific about what it needs (declared in the config/environment.rb file), then if it doesn't run, checkout the stack traces to see where its failing.
In my experience this is not par for Rails development.
While using gems read the README file on github project repos and have a look at the issues and wikis....that should give you a fair idea of which gem is compatible with your Rails version. Regarding the framework, it is pretty stable....major bugs or patches or releases are reported on weblog.rubyonrails.org
Things grow incrementally with each release and that is obvious. There are some deprecations which are well documented in the Rails code and are reported when you run the code.
Rails itself is pretty bug free. I've not witnessed a bug in the framework itself now for a while unless I've been duplicating open tickets.
Where the problems you're seeing have crept in have been over a couple of different areas:
We've moved as a community from Ruby 1.8.x to 1.9
over the last year or so, and some
gems have specific Ruby version
requirements you need to check out
before using them. Most of the more
popular gems are fine and tested to
work in multiple environments. Read the docs first.
Rails itself has matured
significantly over the last few
years, and that has meant many
features have been deprecated. Lots
of plugins out there were written
for an older version of the
framework and expect behaviour that
just isn't valid any more. Read the docs first.
Several different Ruby interpreters
are now available (which is great),
but these sometimes can have an
impact when it comes to 3rd-party
code, but that's rare. Basically,
some gems and plugins expect to be
running on a specific interpreter.
None of the really popular ones are
like this, but you need to be aware
some gem builders are idiots. Read the docs first.
You might notice there is a common theme to the end of each point: read the docs first. :-)
I would say your experience is not at all typical of most Rails developer's workflows, although we've all had a day of struggling from time to time.
You will learn quickly which gems to trust, which ones you'll need but may struggle with from time to time (mysql - building that kills me on OS X, every time), and which ones you should avoid.
Overall though, the development cycle is more fluid (and you'll develop more rapidly) with Rails once you've got your bearings and are adopting good practice. There's a reason why we all like TDD and BDD though - if nothing else it helps us get through a gem update knowing stuff still works when a developer we don't know has done something moronic. :-)

What are the benefits of using the Rails gem instead od vendor/rails?

I recently started working on a small personal project in Ruby on Rails, and have run into a few things that I couldn't find definitive answers for. If anyone here is knowledgeable enough to help, that would be greatly appreciated. All of my questions are below:
What benefit is there to using the Rails Gem instead of having it in vendor/rails?
Is there any benefit to using Rails 2.3.2? Some of the plugins I hoped to use don't seem to be compatible with 2.3.2 (ActiveScaffold)? Does it offer a great improvement over 2.2?
What is the benefit of using Ruby 1.9? Many plugins aren't yet compatible. Does it offer a great improvement over older versions?
Thanks for any help you guys might be able to offer.
vendor/rails probably makes your project more portable. Deployments that run the rake gems:install can act kind of wonky, especially if you upgrade a "Framework Gem" (you have to do these manually).
The downside to vendor/rails is that it makes your deployment slightly bigger (more files that have to be pushed) but if you use git and something like Capistrano, this only bites you on the initial deploy... but its not that bad.
I don't think there are any huge benefits; it just depends on if you need features from 2.3.2. Obviously you want to try to run the latest version to make upgrades less painful. I've found that you always need to be upgrading the framework underneath Rails if you want to have any change of upgrading in the future.
Performance. As you pointed out though, a lot of plugins are broken. This is sort of a chicken-and-egg problem but overtime this should fix itself. We're not running 1.9 yet in any of our production apps because its too unstable with the rest of the stack.
I'll address the gem question.
I've used vendored gems in the past but I have pretty much moved away from it except in the rare case where I need to fork a gem to customize it for some purpose in which case I would vendor the gem.
The main reason not to vendor from my perspective is that you can't cleanly vendor any gems with C modules since they require compilation.
A really good option is to use a gem management tool such as geminstaller, it lets you configure the gems and specific versions of gems that your project works against so that you have a consistent set of gems on your deployment.
What benefit is there to using the
Rails Gem instead of having it in
vendor/rails?
The biggest benefit is that you do not carry around the full rails source code with your project, the other benefit is that moving to a newer version of rails is going to involve less effort.
Keep in mind that the gem command will allow you to install a specific version of a gem.
Is there any benefit to using Rails 2.3.2? Some of the plugins I
hoped to use don't seem to be
compatible with 2.3.2
(ActiveScaffold)? Does it offer a
great improvement over 2.2?
A lot has changed from rails 2.2 to 2.3.2, there are also a bunch of security, performance and bug fixes. ActiveScaffold is compatible with rails 2.3.2, as are most of the plugins out there. If you are starting a new project I would recommend using the latest and greatest.
What is the benefit of using Ruby 1.9? Many plugins aren't yet compatible. Does it offer a great
improvement over older versions?
Ruby 1.9 is much faster than Ruby 1.8.x, however adoption of 1.9 is not that high. Rails 2.3.2 works just fine on Ruby 1.9, however there are some plugins and gems that do not. Make sure you read this stackoverflow question on the topic.

How can I create an all-in-one installer for Ruby on Rails application deployment on Windows?

I'm in the process of deploying a rails application to Windows machines. I do all of my development with OS X and Linux, but the final app will actually run on Windows machines.
That said, my client is looking for an all-in-one Apache(I had to talk him out of IIS)+Rails+Application deployment/installer. He wants to hand all of his (Windows-based) clients an install CD for their respective servers (they all want their own setup).
Is there anything like this in existence? I realize Capistrano exists but that requires a great deal of setup on the hosts (especially for Windows) beforehand and it's not very feasible in this particular case.
In the past I've used InnoSetup (http://www.jrsoftware.org/isinfo.php) for creating installers, but I'm not sure that's going to work in this case.
If you guys have any input, suggestions, or highly persuasive client techniques (to talk them all out of Windows =P) it would be most appreciated.
Best.
Try with RubyStack:
BitNami RubyStack is an installer that greatly simplifies the installation of Ruby on Rails and its runtime dependencies. It includes ready-to-run versions of Ruby, Rails, MySQL and Subversion as well as a number of third-party libraries like FiveRuns TuneUp. RubyStack is distributed for free under the Apache 2.0 license and has been packaged using BitRock's multiplatform installer.
http://bitnami.org/stack/rubystack
I'd look into using jruby with glassfish. Make sure the users have java and it should be good to go.
RubyStack is the closest thing to what you're after, although you might need to tailer the install a bit and remove some unwanted baggage. I don't know of any other Windows projects for a production environment (InstantRails is designed for development).
Maybe you can make InstantRails meet your needs.
Ruby and thus Ruby on Rails is a fairly notorious deployment on Windows even in the best of circumstances, moreso when the setup is out or your hands like that. I don't mean to admonish, but this definitely speaks to matching development and deployment enviroment (I once ran into similar problems when I found out that the Java enviroment we were deploying to was a good half-a-decade out of date).
As I don't have enough Ruby-on-Windows experience to fairly weigh in on the matter, I'd say either LiveCD's or CygWin deployments may be worth looking at (Always good to broaden people's view on alternate Operating Systems, right?).
Have you considered building a single version that runs in a VM?
For this particular problem, I'd go with a traditional Windows installer package like NSIS.
When I had a client with a Windows-only IT department, though, I found they were much more amenable to an XServer than a linux server. I don't generally think of OS X as a server OS, but it actually worked really well. I tried for linux first, and when they shot it down, I suggested OS X and they jumped at it.
It helped, I think, that they already supported some Mac laptops.
Good luck!
As other posters have suggested, RubyStack should be a good option. It is free and you can always use it to run your own 'post install' scripts to customize it for what you want. If you want a supported stack or addition/modifications to RubyStack you can get commercial support from BitRock We have done so for several Rails based companies that wanted a local version, including for the guys over at GitHub

Resources