some gotchas

wiseleyb Feb 9, 2011

Works

named_scope :public, :conditions => "public = true"

Works

PUBLIC_CONDITIONS = "public = true"
named_scope :public, :conditions => SomeModel::PUBLIC_CONDITIONS

Works

named_scope :public, lamba { {:conditions => SomeModel.public_conditions} }
def self.public_conditions...

Passing a block with methods

tinogomes Jan 28, 2011 1 thank

==== Code example

Google = Struct.new(:address) do
def latitude
  -1
end

def longitude
  -2
end

def with_address
  "with #{address}"
end
end

g = Google.new("Some Addres")

puts g.address
puts g.latitude
puts g.longitude
puts...

Disable STI

gabeodess Jan 11, 2011 5 thanks

I had to add "self.inheritance_column" as opposed to simply "inheritance_column" to get this to work.

==== Code example
class MyModel < ActiveRecord::Base # disable STI self.inheritance_column = :_type_disabled end

Passing in parameters

wiseleyb Jan 5, 2011

If you want to pass in parameters you can do it like this:

User.get(:find_by_name, headers = {:name => "bob"})
=> /users/find_by_name.xml?name=bob

For nested routes...

routes.rb resources :companies do resources :users do member do get :find_by_name end en...