Translate

August 29, 2012

How to install Ruby on rails in Windows 7

Introduction:
This is a step by step tutorial that will let you install Ruby on rails 3 in your Windows 7. These steps ease the installation process.

Steps:
  • Download Ruby Windows installer from ruby-lang.org
  • Select version 1.9.3, which is the most recommended and stable release for Windows. 
    When installing this software, make sure to check "Add Ruby to PATH".
  • After installing Ruby, open CMD and check if you Ruby is accessible by executing the following command:
  • ruby -v

    If it works fine you should see the version number of Ruby
  • Then check if you can access gem command by executing:
  • gem -v
  • As you will see, probably the gem version installed by default if this is not the latest, you need to update gem like this:
  • gem update --system
  • Now you are ready to install Ruby on rails, without rdoc and ri documents. By executing following command
  • gem install rails --no-ri --no-rdoc

    Ruby on rails works with SQLite by default but we will use MySQL.
  • In order to let you use both, let us download SQLite and then configure MySQL.  Download SQLite dlls from sqlite.org, unzip them and copy them to:
  • c:\<your_ruby_dir>\bin
  • Now you should install SQLite gem:
  • gem install sqlite3-ruby
  • Now it is time for MySQL. Go to the MySQL website and download the community edition and after installing it in your OS, download this libMySQL.dll and copy it into the same location you put the SQLite dlls
  • c:\<your_ruby_dir>\bin
  • Now install the MySQL gem. To install the mysql gem execute:
  • gem install mysql
  • Now we are ready to create a testing project in rails. Since we are going to use MySQL as DB, we should then execute:  
  • rails new my_first_project -d mysql

August 15, 2012

Missing gcc-4.2 on Mountain Lion

Missing gcc-4.2 on Mountain Lion

I've seen reports of missing /usr/bin/gcc-4.2 on OSX 10.8 (Mountain Lion). Some have tried to reinstall xCode and that worked for them.

I got this when I was trying to install gem
    make
    ....
    make: /usr/bin/gcc-4.2: No such file or directory
    make: *** [bcrypt_ext.o] Error 1
    

Executing following command solved problem on my system.

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

apple-gcc42 installs its gcc-4.2 binary into /usr/local/bin (or wherever you installed Homebrew), not /usr/bin.
Your ruby gems are probably trying to use gcc-4.2 because ruby configures itself to build C extensions with whichever compiler built ruby itself. If you built ruby using gcc-4.2 on an older version of Xcode when that still came with gcc-4.2, that would explain why it's looking for that specific path. Reinstalling ruby with /usr/local/bin/gcc-4.2 would fix the problem.

Note: Linking /usr/bin/gcc to /usr/bin/gcc-4.2 is not perfect way, This is simple trick.

August 14, 2012

Install RVM, Ruby, Ruby on Rails on OS X Mountain Lion 10.8

OS X Mountain Lion was released for all users in the Mac App Store.
Here are some of the things you should consider as you make the switch to this shiny new operating system.

After I downloaded the 4GB installer from the Mac App Store, the whole upgrade process took me about 45 minutes on my 13" 2012 Macbook Pro. It was a simple and straightforward process as the installer takes care of everything.

Once the installer is done, we need to do some additional work to get up to speed once again and be able to compile Ruby (using RVM) or install packages using Homebrew.

Install Xcode + Command Line Tools
You can get Xcode from the Mac App Store. You'll need at least version 4.4 of Xcode for it to work with OS X Mountain Lion. After the installation, open up Xcode in your /Applications folder. You'd want to go to Xcode -> Preferences -> Downloads tab then install the "Command Line Tools". After you're done, quit Xcode and fire up Terminal.

After the upgrade, Apple will set the ownership of your /usr/local folder to root. You can easily fix this by running this command in Terminal:

sudo chown -R `whoami` /usr/local

Next, you need to update Homebrew:

brew update

To install any Ruby that's older than 1.9.3 like 1.9.2, 1.8.7 etc.
You'll need to install GCC 4.2. Apple does not ship the Command Line Tools with gcc-4.2 compiler anymore,
You need to install it via Homebrew. By default, Homebrew doesn't include any formula that ships with the OS in the main repository, so you'll have to enable homebrew-dupes repository by using brew tap

  brew tap homebrew/dupes
  brew install apple-gcc42 

If you were using a binary package from MySQL website to install your MySQL server, you will need to change the ownership of your MySQL data directory back by issue this command:
sudo chown -R mysql:mysql `brew --prefix`/mysql
Word to the Wise: Backup Your System
Before performing any major upgrade, always make sure that you have the latest backup of your Mac.

August 10, 2012

*** Textmate 2 - Open Sourced ***

One of most known code/text editors on OS X went open source. Since yesterday TextMate 2 is available on GitHub.

Allan Odgaard's TextMate has been a beloved text editor since 2004 and one of gem of Mac's favorite apps for about just as long, but since 2009, development on the app has slowed to a crawl: three years ago, Odgaard said TextMate 2 was about 90% complete, but it didn't hit the web until end of year 2011, also a final version still hasn't been released.

In a surprise (and very awesome move), its source code has: TextMate 2 is going open source.

If you're interested in tinkering or even compiling TextMate 2 for yourself, you can grab it on GitHub.

Legal
The source for TextMate is released under the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
TextMate is a trademark of Allan Odgaard.

July 26, 2012

OS X 10.8 Mountain Lion

Apple have released their latest addition to the OS X family with version 10.8, also known as "Mountain Lion". This new version brings with it a whole host of improvements, most of which focus on bringing features such as the Notification Center and iCloud from iOS to the Mac. In addition to those new features, 10.8 also includes system wide refinements, which make the OS feel like what Lion should have been.

The inclusion of some new apps which started their lives on iOS. If you've used iOS before, these "new" apps shouldn't really feel all that "new". Notes, Reminders, and, Game Center are all nearly identical clones of their iOS counterparts, with a more grown up feel on the Mac desktop.

You can store the notes you create either locally or sync them with iCloud. Reminders works just like you'd expect, and is even is able to tap into your location (presumably based on your WiFi and IP address) and deliver reminders either when arriving at or leaving a location. Similar to the iOS version of the app, Reminders also lets you set reminders for a specific date and time. 

End users now have a notification system that is both integrated and easy to use, and programmers have one consistent way for their apps to send notifications.

-It includes the ability to mirror your Mac's screen to an AppleTV or any other AirPlay receiver.

-Users with an AppleTV on the same WiFi network as their Mac will notice an AirPlay icon appear in the bar; simply click the icon and select your AppleTV to get started. You will see your Mac's desktop on the big screen. (WoW)

-New improved Messages

-Better iCloud File sharing

- Enhanced sharing capabilities - From the "Mail, Contacts & Calendars" screen in System Preferences, users can now set up Twitter, Facebook, Flickr, and Vimeo accounts with the OS.

OS X Mountain Lion includes system-wide refinements for just about every app. After installing the OS on my computer, everything just seemed to work a little bit better. 

May 1, 2012

Howto- Install PostgreSQL in Ubuntu 11.10/12.04

  • Install PostgreSQL in Ubuntu, some instructions are given below, Install postgresql using the command on terminal:
  • sudo apt-get install postgresql  libpq-dev
    
  • By default postgres is listening on port 5432. You need to confirm that after installation check that postgres is listening on port 5432
  • To check postgres is really listening on port 5432 use following command on terminal:
  • netstat -atn | grep -v tcp6 | grep 5432                          
    tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN  
    
  • If you see above output, then postgres is installed successfully on your system. You need other configurations to interact with postgres. First you need to create new db user to access the postgres, Default db user postgres is created when you install the postgres.
  • Now change the postgres user password (as root):
  • Make first database user (a superuser is required for practical migrations) in postgres!:
    sudo su postgres                                                   
    createuser pankaj                                                  
    Shall the new role be a superuser? (y/n) y
    
  • Now create a postgres database Create a first postgres development database
  • ~> pssql template1 
    psql (9.1.3)
    Type "help" for help.
    
    template1-# \l
                                      List of databases
       Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
    -----------+----------+----------+-------------+-------------+-----------------------
     postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
     template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
     template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
               |          |          |             |             | postgres=CTc/postgres
    (3 rows)
    
    template1-#
    
    template1=# CREATE DATABASE dummy_development;
    CREATE DATABASE
    template1=#
    template1=# \l
                                         List of databases
           Name       |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
    ------------------+----------+----------+-------------+-------------+-----------------------
     postgres         | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
     dummy_development| pankaj   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
     template0        | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                      |          |          |             |             | postgres=CTc/postgres
     template1        | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
                      |          |          |             |             | postgres=CTc/postgres
    (4 rows)
    
    template1=#\q
    
    ------ TO Quit use \q
    
Ruby on Rails developers:
  • Install the postgres gem
  • dummy git:master> gem install pg                      
    Building native extensions.  This could take a while...
    Successfully installed pg-0.13.2
    
  • To install GUI client pgsql
  • sudo apt-get install pgadmin3
    

April 18, 2012

Difference between update_attribute and update_column


We use update_attribute most of the time, update_column serves same purpose, there is below difference
  • update_attribute
  • It updates the single attribute with bypassing the validations.
  • update_column
  • It updates the single attribute with bypassing the validations as well as the callbacks.

Syntax of both are as follow:
Model.update_attribute :field, 'value'
Model.update_column :field, 'value'

update_column is added in the rails 3.2.1

In case if you need to use update_column in lower Rails version then you can apply simple patch given below.

module ActiveRecord
  module AttributeMethods
    def update_column(name, value)
      name = name.to_s
      self.class.update_all({ name => value }, self.class.primary_key => id) == 1
     end
   end
end

Related posts:
Difference between update_attribute and update_column 
What is different in update_all, update,  update_attribute, update_attributes methods of Active Record
Difference between .nil?, .empty?, .blank?, .present? 
render vs redirect_to in Ruby on Rails

About