Flowdock

Notes posted by magnemg

RSS feed
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.