venerdì 29 aprile 2011

jQuery on Rails 3

Ruby on Rails is an open source web application framework for the Ruby programming language. The last version of this framework is the 3.0.0 released Aug 29, 2010. By default, when you start a new Rails application with:
rails new my-app
by default it uses prototype as javascript framework. Now prototype isn't the best solution for all developers so you might want to use jQuery instead.
To use jQuery you need to create a new rails application with the following command instead:
rails new my-app -J
notice the "-J" option that skips the creation of the prototype files in the new app.
Now you have to download jQuery from its website and put the jquery-x.x.x.js file inside the public/javascripts folder of your application.
Now download the file rails.js from http://github.com/rails/jquery-ujs and put it inside the public/javascripts folder too.
Now you need to add a reference to jQuery inside the application layout. To do so, open the file app/views/layouts/application.html.erb and add the following code:
<%= stylesheet_link_tag 'jquery-ui-1.8.5', 'scaffold' %>
<%= javascript_include_tag 'jquery-1.4.3', 'jquery-ui-1.8.5', 'application' %>
You're done! Now you can use Ruby on Rails with jQuery.
Happy coding!

giovedì 28 aprile 2011

Basic GIT configuration

Git is a distributed revision control system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development. Once you installed Git, you may configure some basic parameters like username, email, ecc. To do so you can use the following commands:
Set the username:
git config --global user.name "pinco pallino"
Set the user email:
git config --global user.email "foo.bar@somehost.com"
Enable the ui color option:
git config --global color.ui true
Hope this helps

martedì 26 aprile 2011

How to start/stop/restart delayed_jobs from the command line

Delayed Jobs is a background processing tool written in ruby. When you use it inside a Ruby on Rails application, usually you start it with:
rake jobs:work
If you need to start delayed jobs from a Capistrano task or from a monitoring framework like God, you should use the following commands.
To start:
script/delayed_job start
To stop:
script/delayed_job stop
To restart:
script/delayed_job restart

Hope this helps.

mercoledì 20 aprile 2011

How to enable WebGL support in Firefox 4 (Linux)

WebGL is a Web-based Graphics Library. It extends the capability of the JavaScript programming language to allow it to generate interactive 3D graphics within any compatible web browser.
To enable WebGL support in firefox 4 using Ubuntu 10.04 you have to install the library libosmesa6 with the following command:
sudo apt-get install libosmesa6
After this start up firefox and in the url bar type:
about:config
and press enter. Say ok to the alert message and in the search box type "webgl". Double click on "webglosmesalib" parameter and enter the library path (like in the screenshot below).
Enabling Firefox 4 WebGL support.

For me it's:
/usr/lib/libOSMesa.so.6
Now quit and restart Firefox and WebGL support shoul be active.
Enjoy!

mercoledì 6 aprile 2011

How to remove all Rubygems inside a RVM gemset

The only way to uninstall all the gems inside a RVM gemset is to use the following command:
$ rvm use 1.9.2@my-gemset
Using /home/user/.rvm/gems/ruby-1.9.2-p180 with gemset my-gemset
$ gem uninstall gem1 gem2 gem3 ...
A bit boring, don't you think? A way to automate this process is through the following command:
gem uninstall `gem list | cut -d" " -f1 | tr '\n' ' '`
If you don't use RVM to manage different Ruby versions, maybe you have to change the command above in something like this:
sudo gem uninstall `sudo gem list | cut -d" " -f1 | tr '\n' ' '`
Pay attention to copy all the "`" characters.
In this way you can uninstall all the gems only with one command.
Hope this helps :-)