rails searchlogic_test
cd searchlogic_test
script/generate model category name:string
script/generate model product category_id:integer name:string
Add to db/seeds.rb
Category.create(:name=>"first category")
Setup the database
rake db:migrate
rake db:seed
Add to config/environment.rb
config.gem "searchlogic"
Models
app/models/product.rb
class Product < ActiveRecord::Base
belongs_to :category
named_scope :some_scope, {:conditions=>{:name=>""}}
end
app/models/category.rb
class Category < ActiveRecord::Base
has_many :products
end
Setup the database
rake db:migrate
rake db:seed
Test on console
script/console
Category.first.products.some_scope.ascend_by_created_at
NoMethodError: undefined method ascend_by_created_at' for []:Array from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:149:insend'
from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:149:in send' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:186:inmethod_missing'
from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/base.rb:2182:in with_scope' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:207:insend'
from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:207:in with_scope' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:118:insend'
from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:118:in with_scope' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:179:inmethod_missing'
from (irb):16
but Category.first.products.ascend_by_created_at.some_scope - works correct
Create a project
Add to db/seeds.rb
Setup the database
Add to config/environment.rb
Models
app/models/product.rb
app/models/category.rb
Setup the database
Test on console
script/console