Notes posted by magnemg
RSS feed![Default_avatar_30](https://www.gravatar.com/avatar/0475394dd283efd42d1ae51379c9ed00?default=http://apidock.com/images/default_avatar_30.png&size=30)
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 >>
![Default_avatar_30](https://www.gravatar.com/avatar/0475394dd283efd42d1ae51379c9ed00?default=http://apidock.com/images/default_avatar_30.png&size=30)
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
![Default_avatar_30](https://www.gravatar.com/avatar/0475394dd283efd42d1ae51379c9ed00?default=http://apidock.com/images/default_avatar_30.png&size=30)
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.