I try to override the default find method for some of my models:
I want it to find only the users, which belong to a specific customer.
Therefore I set an application-wide instance variable before rendering
anything else:
class ApplicationController < ActionController::Base
before_filter :cid, :uid
def cid @cid ||= session[:customer_id] if logged_in?
end
end
My model should do the following (but it doesnt work this way):
class User < ActiveRecord::Base
with_scope :find, :conditions => {:customer_id = cid}
…
end
I know that accessing the session in models isn’t beatifull - so I
tied via the application-method…
Can somebody help me?
Yeah, but this ins’t working either… When i try with:
class User < ActiveRecord::Base
with_scope :owning, :conditions => {:customer_id = cid}
…
end
the following error occurs:
…
…
** Starting Rails with development environment…
Exiting
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:1667:in method_missing_without_paginate': undefined local variable or methodcid’ for #Class:0x23ae54c (NameError)
Or do I missunderstand you? (sorry, my english is very bad)