Flowdock

Notes posted by magnemg

RSS feed
February 18, 2015
0 thanks

Not only for strings, but arrays and hashes too

exclude? is defined as !include?, meaning it is the exact opposite of include? . See the source.

This means that it works for Arrays and Hashes too, as well as for Strings.

It works for Arrays:

>> [nil].exclude?(nil)
=> false
>> [nil].include?(nil)
=> true
>> ["lala"].include?(nil)
=> false
>> ["lala"].exclude?(nil)
=> true

And for Hashes:

>> params = {}
=> {}
>> params[:db] = "lol"
=> "lol"
>> params.exclude?(:db)
=> false
>> params.include?(:db)
=> true
>> 
July 11, 2014
1 thank

Use this for has_one associations instead

I have confirmed that validates_associated doesn’t work with has_one associations, like @amasses said.

This however worked for me, so I recommend to use validates on the has_one association directly, like this:

class Book < ActiveRecord::Base
  has_one :cover, validates: true
end
January 5, 2012 - (>= v3.0.9)
0 thanks

How to include a “Please select…” (default/prompt) in a grouped dropdown list.

The clue here is that you actually specify the prompt on the select element, and not in the option_groups_from_collection_for_select element.

<%= f.select :post_type_id,   option_groups_from_collection_for_select(@categories, :post_types, :name, :id, :name), :include_blank => "Please select..." %>

Hope this helps someone.