Saturday, March 31, 2012

Install Rails 3 using RVM on ubuntu


1. Installing RVM

Ruby Version Manager is a great tool for isolating your development environment to each individual project.  This allows you to have specific ruby versions with specific gemsets isolated from the rest of your development environment, virtually eliminating any potential conflicts.  Although not absolutely required to use Rails or Ruby, RVM will greatly reduce headaches with managing ruby.  To learn more about RVM, visit the RVM homepage.
Luckily, RVM provides an install script that we can download and execute with a single command.  This command will download the latest code from the github repository, so you need to have git and curl installed on the system.  If you are using a recent linux distro like Ubuntu 11.10, then you might already have git and curl installed. If not, execute the following command:

>$ sudo apt-get install git curl
Start the RVM installation by running this command:

>$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

Friday, March 30, 2012

Devise gem for Authentication in Rails 3

Devise Authentication in Rails 3

 Devise gem features:
  • Database Authenticatable: encrypts and stores a password in the database to validate the authenticity of an user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
  • Token Authenticatable: signs in a user based on an authentication token (also known as “single access token”). The token can be given both through query string or HTTP Basic Authentication.
  • Confirmable: sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
  • Recoverable: resets the user password and sends reset instructions.
  • Registerable: handles signing up users through a registration process, also allowing them to edit and destroy their account.
  • Rememberable: manages generating and clearing a token for remembering the user from a saved cookie.
  • Trackable: tracks sign in count, timestamps and IP address.

Thursday, March 29, 2012

Rails 3.2.3.rc1 has been released!

Rails 3.2.3.rc1 has been released.

IMPORTANT

This release changes the default value of config.active_record. white-list_attributes to true. This change only affects newly generated applications so it should not cause any backwards compatibility issues for users who are upgrading but it may affect some tutorials and introductory material. For more information see the mass assignment section of the ruby on rails security guide We've also adjusted the dependencies on rack-cache and mail to address the recent security vulnerabilities with those libraries. If you are running a vulnerable version of mail or rack-cache you should update both gems to a safe version. We also fixed a couple of regressions in the render method.
If there are no release blockers, then I will be releasing the final version on March 30th. If you find something please open an issue on github and let me know through email (santiago at wyeworks.com), tweet (spastorino) or cc me on the github issue.

CHANGES since 3.2.2

Action Mailer
  • Upgrade mail version to 2.4.3 ML
Action Pack
  • Do not include the authenticity token in forms where remote: true as ajax forms use the meta-tag value DHH

How to develop rails plugin from scratch?...

How to develop rails plug-in from scratch?

Generate Plug-in with command: 

     >$ rails generate plugin hello_world

It will create file system as bellow:
- lib
    - hello_world.rb
- tasks
    - hello_world_tasks.rake
- test
    - hello_world_test.rb
- init.rb
- install.rb
- uninstall.rb
- README
- Rakefile
- MIT-LICENSE

init.rb will be executed every time when your application runs. Generally hook code is to be included here like you want to make all methods of your plugin available in your app’s models, controllers, views and helpers

Example:
#All methods in module HelloWorld will be available in all #model’s object
ActiveRecord::Base.class_eval do
    include HelloWorld
end

Ruby on rails installation on ubuntu

1. What is Rails ?

Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern. From the Ajax in the view, to the request and response in the controller, to the domain model wrapping the database, Rails gives you a pure-Ruby development environment. To go live, all you need to add is a database and a web server.

2. How to Install it on Ubuntu ?

2.1 First we need to install Ruby and irb (Interactive ruby shell) and we'll add ri and rdoc. The recommended Ruby version for rails is 1.8.5.
      Open your terminal and type: 

     >$ sudo apt-get install ruby irb ri rdoc ruby1.8-dev
To check Ruby version

     >$ ruby -v
2.2 Then we need to install RubyGems. RubyGems is installed from tgz file.We are going to install RubyGems with the following command

Wednesday, March 28, 2012

Intro to Ruby On Rails

What is Ruby ?

Before we ride on Rails, let's know a little bit about Ruby which is the base of Rails.

Ruby is
  • A High Level Programming Language
  • Interpreted like Perl, Python, Tcl/TK.
  • Object-Oriented Like Smalltalk, Eiffel, Ada, Java.
  • Originated in Japan and Rapidly Gaining Mind-share in US and Europe.

Why Ruby ?

Ruby is becoming popular exponentially in Japan and now in US and Europe as well. Following are greatest factors: