Ok,
I should have mentioned - I am running rails 2.0.2 and hence running
Streamlined edge.
I tried the with_scope method - albeit in a slightly different way due
to with_scope being protected. This means you can only set scope from
the model.
I tried a few things, and I couldn't seem to get the scope to execute
correctly.
Here is the example I used.
Model: Thought
DB Schema (so you know the model fields)
create_table "thoughts", :force => true do |t|
t.string "value"
t.datetime "date"
t.datetime "created_on"
t.datetime "modified_on"
t.integer "user_id"
t.integer "position"
end
In the Thought_Controller I tried
around_filter :scope_by_user, :only => [:list, :index]
def scope_by_user
Thought.with_scope(:find=>{:conditions=>"user_id=1"}) { yield }
end
And got error: protected method `with_scope' called for #<Class:
0x25a0378>
This seems to be because with_scope is protected in rails 2.0.2
So then i edited crud_methods.rb and I changed
models = model.find(:all, @options)
to
models = model.find_scoped(:all, @options) for testing.
Then in the thought model:
def self.find_scoped(*args)
with_scope(:find=>{:conditions=>"user_id=1"}) do
find(*args)
end
end
Even with this - the scope still does not apply and I see other user
ID's in the view.
Any Ideas?
Thanks,
Ben