Thursday 16 June 2011

Identify user's location [ Region/Sub Region ] based on IP address

 Your current best bet is probably GeoKit (http://github.com/andre/geokit-gem for gem, http://github.com/andre/geokit-rails for plugin). It has built in functionality for Yahoo and Google API keys, distance calculation helpers, reverse geolocation, etc.  Also Can find basic information of an IP like street_address, city, state,  zip etc. (As needed)
Please find details here http://geokit.rubyforge.org/api/geokit-gem/Geokit/GeoLoc.html

Friday 29 April 2011

Steps to vendor rails Or upgrade vendor rails in an application

Step 1 # Install Rails required version ( say 2.3.10 ) ( for ubuntu gem install rails -v = 2.3.10 )

Step 2 # To ‘freeze’ your rails gems, simply type the following in your terminal window: rake rails:freeze:gems 
This will create a new folder in /vendor/ called ‘rails’ and unpack all of the core Rails gems.

Step 3 # Instead of having to install the required gems wherever your app goes, your app can pack the gems up and take them with it .

To unpack the required gems simply run rake gems:unpack:dependencies 
This will unpack all of the gems required in your environment.rb file plus any gems they may require into vendor/gems/
 

Step 4 # Now you can uninstall rails ( for ubuntu gem uninstall rails ) . And Your app will have use rails with version 2.3.10


If you decide to unfreeze Rails and revert back to the system installed version instead, simply run

rake rails:unfreeze
This will remove the rails directory from /vendor/ and all of its contents.

Monday 25 April 2011

error for ActionController::InvalidAuthenticityToken (ActionController

Set this in your controller class definition 
                          protect_from_forgery :only => [:create, :update, :destroy]
or add this in current form
                       <%= hidden_field_tag :authenticity_token, form_authenticity_token -%>

Remove Displaying SQL queries on Prompt

Add this line in enviornment/development.rb will not show sql info(queries) on terminal
config.log_level = :info

Saturday 23 April 2011

Process for deploying app on heroku :-

1) sudo gem install heroku
2) heroku create app_name
3) git init
4) git add ( add the files present in the app, see the files by ls command)
5) git commit -m "commit the app"
6) cd ~/.ssh (see that ssh directory exists or not)
     if exists then    
          $ ls
          $ config id_rsa.pub
          $ id_rsa known_hosts
          $ mkdir key_backup
          $ cp id_rsa* key_backup
          $ rm id_rsa*--
      if "not exists" then
          $ ssh-keygen -t rsa -C "your email"
8) heroku create
9) heroku keys:add
10) git push heroku master
11) heroku rake db:migrate.

To see the error in opening the site in the browser
  heroku logs --app app_name ( run that command on the terminal)

if git push heroku master gives following error

------Agent admitted failure to sign using the key.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

then run this on prompt

ssh-add ~/.ssh/id_rsa

Using ActiveScaffold with Rails 3.0


Setup Rails 3 project :
  1. rails new howto
  2. cd howto
  3. bundle install
  4. rake db:create
Setup ActiveScaffold (you will need a running git bash):
  1. rails plugin install git://github.com/vhochstein/active_scaffold.git
  2. rails g active_scaffold_setup [prototype| jquery]
Your choice if you would like to use prototype or jquery. Thanks to Rails 3.0 and the new unobtrusive Javascript approach. If you are asked if you would like to overwrite rails.js just say yes.
Setup two activescaffolds:
  1. rails g active_scaffold Team name:string position:integer
  2. rails g active_scaffold Player name:string injured:boolean salary:decimal date_of_birth:date  team:references
  3. rake db:migrate
  4. edit file app/models/team.rb -> has_many :players
  5. edit file /app/views/layouts/application.html.erb->     
    <%= javascript_include_tag :defaults %>
    <%= active_scaffold_includes %>
  6. Add this to ur controller     active_scaffold :<your_model_name>
  7. Add :active_scaffold => true to your routes: by writing his in /config/routes.rb        
    map.resources :users, :active_scaffold :user
  8. rails s
  9. Open Browser: http://localhost:3000/teams
That ‘s it. You ve got a running application to CRUD teams and players using Rails 3 and ActiveScaffold.

Singular Plural In Rails

Keep Following things in mind : -
1) The database table is plural.
2) The model is singular, and associations are pluralization sensitive
3) resource-based controllers should be plural (which means the directory for the views and the helper is also plural).
4) The route name and the urls it generates/recognizes are plural.