How to get current_user in model and observer Rails

If you want to log the user who created, updates and delete a object in specific model.There is no default way to fetch the current user in models, current_user is always assigned in controllers (as per authentication plugins, restful_authentication, authlogic and devise). Found one way, by adding some steps in model/user.rb, we can get the […]

Model Relationship in “rails-backbone”

Introduction Backbone-associations provides a way of specifying one to one and one to many relationships between Backbone models. Additionally, parent model instances (and objects extended from Backbone.Events) can listen in to CRUD events on any children – in the object graph – by providing an appropriately qualified even on deeply nested object graphs – and […]

Scope in model Rails 3.X

Purspose Complex queries in controller make application hard to maintain. Move them into the model as named_scope or scope(Rails 3.X) make the controller simple and the complex find logics are all in models. Suppose we have in controller, class JobsController < ApplicationController     def index         @published_jobs = Job.find(:all, :conditions => { :status […]