FREEZE GEMS IN RAILS 3 APPLICATION

I have seen lots of forum, where developers keep on asking: “How would I freeze the gems to my Rails-3 application?”

Take this URL for example: http://bit.ly/gFzN6Z

One developer says that: localize your gems by running this command: bundle install –vendor/gems

Others refuses to go with this way. Here’s why?

  • We are moving away from the concepts of bundler
  • This will install the gem dependencies as well in your vendor/gems directory, which we don’t need at all. We need only those gems which are specific to our application.
  • You don’t need to unpack the gems and check them in to your app, because it doesn’t matter: you’re guaranteeing the same versions are being called regardless of where they are installed, which will likely vary from machine to machine anyways (.bundle/ should not be checked in to the repo) – so why stick another 60-80 MB of files into your repo that you won’t ever be changing or using?

So, there is no way you can localize your gems in a Rails-3 application. There are other ways you can perform in order to better use of bundler gem.

  • Use specific versions in your Gemfile and run bundle install –deployment on each target system where you need the exact gem versions.
  • While defining a new gem in Gemfile, assign a path to it. For example:
    gem 'paperclip', '2.3.15', :path => './vendor/gems/paperclip-2.3.15'
    Bundler will assume that it has to get the gem from vendor/gems folder. Once you’re done. run bundle install
Advertisements

DON’T HESITATE TO TRY OUT NEW THINGS IN RUBY

Since last couple of months, I was trying installing Rails-3 on my Windows PC.
When I heard, that Rails-3 requires ruby-1.8.7 or higher, I instantly removed Ruby-1.8.6 and all its components and installed 1.8.7 from the fresh point.

I was happy, as my new system has Rails-3 now… Wow, what else I need?

But later, I found that my few of my old applications, which requires ruby-1.8.6 have stopped working. WTH!! Can’t it work with Ruby-1.8.7 now? With the investigation, I observed that, there were few libraries which were specific to 1.8.6 version and are not in 1.8.7 now. Some of them, I restored from 186 to 187 but were not compatible. Urrrgghhh!!! I am disappointed :-(

Now, I need some sort of version Manager, which will handle multiple version of Ruby. From here my search starts!!

After searching a lot on Google, and suggested by one of my friend, I found ‘pik‘.
Short Intro about PikPik is a version manager for Ruby. You can handle/install multiple versions of Ruby and switch between them easily.

Basic Requirement: You must have atleast one version of Ruby, up and running on Windows.

Installation: ‘pik’ comes as a gem. To install pik, follow these steps:

Dependencies:
> my current plateform: ruby-1.8.6. From the command prompt, type:
gem install pik
> After the successful installation of pik, type:
pik_install C:\tools
> Add this to your Path Environmental variables
My Computer > Right Click > Properties > Advanced System Settings > Environmental Variables > Path

Once you’re done. Open a new command prompt and type:
pik list
It will add the current version of ruby into the list.
Now what’s so special about pik? How it can handle the multiple versions? To see that in action, in command prompt, type:
pik install ruby 1.8.7
and this will start downloading and once downloaded it will install 1.8.7, under:
C:\Users\PC-name\.pik\rubies\Ruby-187-p302

Awesome!! isn’t it?
pik list
It will show you the current version of ruby and the other ones.
pik use 187
Will use now ruby-187. Don’t believe me? :-x Then type:
ruby -v

I am super excited now :-D I want to install Ruby-1.9.2 now. Afraid? Still hesitate? Don’t be, just follow the instructions…
From the command window, type:
pik install ruby 1.9.2
Heights of happiness… It is installing 1.9.2 now!!
Path will remain the same, i.e:
C:\Users\PC-Name\.pik\rubies\Ruby-192p302

Do a pik list now and you’ll see:
<image comes here />

Now, I am running multiple versions of Ruby on my Windows m/c and I can select any version by:
pik use 187
gem install rails --include-dependencies
rails s -p 4000

and can perform numerous operations… Yuppy!!!!

Here comes the another pain. Few days back I thought to work with Rhodes. The Mobile Framework for Ruby.

To install it, I went through the Rhodes website and followed the tutorials. I did:
pik use 187
gem install rhodes

I got make error :-x Why windows won’t work like the Linux does and why do we need to troubleshootC-compiler problems?

Another day I spent to look around for a solution and finally came up with Devkit.

Short Intro about Devkit: Devkit is a windows executable program, which creates native extensions for your Ruby gems, which uses C-complier.

Installation: Download the Devkit (Development Kit) from Ruby installer website. After downloading, extract it to:
C:\devkit
After extraction, open your command, go inside C:\devkit prompt and type:
ruby dk.rb init
This will create the config.yml inside C:/devkit. Now you need to define all the Ruby versions inside that file, so that devkit will create native extensions for them. To do that, open that file and at the end of it, write these lines:

- C:\ruby
- C:\Users\PC-name\.pik\rubies\Ruby-187-p330
- C:\Users\PC-name\.pik\rubies\Ruby-192-p0

Once done save it and from the command prompt, type:
ruby dk.rb install
and you should see something like this:

Awesome, easy steps, isn’t it? Now, what else you’re looking for? Go ahead, install any gem for any version of ruby without any hesitations :-)

Please let me know if you’re stuck or need any help. Good comments will always motivate me to write more and more and help the Ruby Community keep growing.

References taken from:

JQUERY ON RAILS3 AUTO SELECT

In earlier post of mine, we have seen, how to implement “Auto Select”, with the help of Prototype and Rails.

Now, that Rails-3 has been released, lot of changes are already made. In-built support for Prototype has been removed. Still if you wish to use prototype, all you need is to install its gem.

Here, I am covering the same example:

– Select ‘Country’ from the first drop down.
– Second drop down will populate the list of ‘States’. If you select any state:
– Third drop down will populate the list of ‘Countries’.

All I am using here is Rails-3, Rails-3 UJS, and Jquery.

I would also like to thank Ryan Bates, for the railscasts he provided to implement this using unobtrusive javascript.

Please download the application with the link provided and let me know your feedback.

System Requirements/Features Covered in this application.
– Ruby 1.8.7
– Rails 3.0.0 or higher
– Country -> State -> City Drop down
– Ajax Search

Steps to run the application:
– Create a schema. Change the database.yml accordingly.
– Run rake db:migrate
– Start the server.
– Please do read the README file.

jquery-autoselect

Get Yourself Upto date with Ruby 1.9.2 and Rails 3

Hello Everyone,

Today, where lots of people are shifting from older versions of ruby to the newer and stable one i.e 1.9.2 and rails 3. I am also shifting to this, and would like to share my thoughts and opinions about upgrading, its advantages, hurdles and future concerns.

To try this.. I am using both Linux (Ubuntu) and Windows (windows 7).
Let’s cover each topic in detail

  • Setting up Ruby-1.9.2
  • What’s new in Ruby-1.9.2
  • Few of the working ruby code
  • Setting up Rails-3 with Ruby-1.9.2
  • Setting up Passenger or Apache with Rails-3
  • A sample application in Ruby-1.9.2 and in Rails-3, featuring:
      Authentication
      Image Upload
      Pagination
      Facebook Integration
      Twitter Integration
      Google Earth integration
      Post with Title and tags

I may cover this using different articles.

Meanwhile, there is an Rails-3 Application created by me, which is currently on Github. I would request, if someone is interested to see the changes Rails-3 has introduced, please download the application and run it on your local. Here is the path for it: https://github.com/puneetpandey/file_upload

Prerequisites:
1. Ruby 1.8.7 or higher
2. Rails-3
3. Mysql Database