I have some models that need a where condition for every select I do.
Say I have this table:
create_table “posts”, :force => true do |t|
t.string “title”, :default => “”, :null => false
t.text “text”, :default => “”, :null => false
t.integer “user_id”, :default => 1, :null => false
So I want every user to see only his posts. Always.
If I do Post.find() I want to add :conditions => [‘user_id = ?’,
session[:user_id]] for every call to find. I call find in a lot of
actions, like find(params[:id]) or find_by_title(‘hello’) and other
variants of find.
So my questions: can i add my condition to every call to find by adding
it only one time somewhere?