Friday, 24 August 2012

Mongo Restart/connection failure ?






Connection failed during mongo start:


Follow this steps:
  • $   sudo rm /var/lib/mongodb/mongod.lock
  • $   mongod --repair
  • $   sudo start mongodb
  • $   sudo status mongodb
  • $   mongo
                      connection established message will be displayed.  :)

Gem File and Gem Lock file



The Gemfile is where you specify which gems you want to use, and lets you specify which versions.

The Gemfile.lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at theGemfile.lock and install the exact same versions, rather than just using the Gemfile and installing the most recent versions. (Running different versions on different machines could lead to broken tests, etc.) You shouldn't ever have to directly edit the lock file.

Thursday, 23 August 2012

is ajax request (rails)?

if request.xhr?
  # respond to Ajax request
else
  # respond to normal request
end

ajax->success(), complete() methods difference



             All of jQuery's ajax methods return a jqXHR object that provides .error(),.success(), and .complete() methods. So, the difference between.success() and .complete() is .success() only gets called if your web server responds with a 200 OK HTTP header - basically when everything is fine.

                   However, .complete() will always get called no matter if the ajax call was successful or not - maybe it outputted errors and returned an error - .complete() will still get called.


Tuesday, 21 August 2012

Difference between Rails 2.3 and 3


(1) Introduction of bundler (New way to manage your gem dependencies) 
(2) Gemfile and Gemfile.lock (Where all your gem dependencies lies, instead of environment.rb) 
(3) A new .rb file in config/ folder, named as application.rb
 (Which has everything that previously environment.rb had) 
(4) Change in SQL Structure: Model.where(:activated => true) 
(5) All the mailer script will now be in app/mailers folder, 
earlier we kept inside app/models. 
(6) Rails3-UJS support. for links and forms to work as AJAX, 
instead of writing complex lines of code, we write :remote => true 
(7) HTML 5 support. 
(8) Changes in the model based validation syntax: validates :name, :presence => true 
(9) Ability to install windows/ruby/jruby/development/production specific gems to Gemfile. 
group :production do 
 gem 'will_paginate' 
end

JSON



JSON: JavaScript Object Notation.

It is syntax for storing and exchanging text information. Much like XML and is smaller than XML, and faster and easier to parse.

JSON syntax is a subset of the JavaScript object notation syntax.
  1. Data is in name/value pairs
  2. Data is separated by comma
  3. Curly brackets holds objects
  4. Square brackets holds arrays

To validate JSON-

http://json.bloople.net/ with clear pictorial representation

http://jsonlint.com/

Wednesday, 8 August 2012

Polymorphic Associations


polymorphic associations:

                      With polymorphic associations, a model can belong to more than one other model, on a single association. For example, you might have a picture model that belongs to either an employee model or a product model. Here’s how this could be declared

class Picture < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
end

class Employee < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end

class Product < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end