This method won't throw an error: def a_method raise ensure return :something end it will in fact return :something So please proceed with care...

...and complexity in the code is when a functional method (that we expect to return a value) return different values under different circumstances. For example, we ruby programmers have a...

...bad habit of returning nil from a method when certain condition is not fulfilled else return an Array or Hash. That just makes the calling code unnecessary complex and error...

# => {:conditions => "foo2 IS NOT NULL"} As you can see, proxy_options only returns conditions for last scope, but one possible use case of this is using proxy_options...

...data: JSON.stringify(params), }) .done(onDone) .fail(onFail); Always make sure your rails controller returns something: if @property.update_attributes(params[:property]) render :json => { :ok => true }, :status => :ok else render :json => { :ok...

Best results in other decks

An association defined with has_many :through will return the same record multiple times if multiple join models for the same record exist (a n:m relation). To prevent this...

invoice_id product_id 11 1001 55 12 1001 55 Now #products will return the product with ID #55 two times for this invoice: invoice = Invoice.find(1001) invoice.products # => [# , # ]

...IN (?)", excluded_ids) When the exclusion list is empty, you would expect this to return all records. However, this is not what happens: # Broken example User.where("id NOT IN (?)", []).to...

...SELECT `users`.* FROM `users` WHERE (id NOT IN (NULL)) Passing an empty exclusion list returns no records at all! See below for better implementations. Rails 4+ Use the .not method...

Search in all decks