Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Rich Blumer's Profile

GitHub User: rich-ware

Comments by Rich Blumer

Avatar

Hi, I am trying to use this solution in my application but it's not working for me. I am using Mongoid so that is only difference from this example. Here is my code:

class Country
include Mongoid::Document
field :name, type: String
field :abbreviation, type: String

has_many :states
has_many :equipment

end

class State
include Mongoid::Document
field :name, type: String
field :abbreviation, type: String

belongs_to :country
has_many :equipment

end

class Equipment
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paperclip

field :description
field :modelNumber
field :title
field :categoryId
field :subCategoryId
field :city
field :askingPrice

belongs_to :country
belongs_to :state

has_mongoid_attached_file :photo

embeds_many :questions do
def find_by_id(question_id)
where(question_id: question_id).first
end
end

end

<%= form_for(@equipment) do |f| %>

<%= f.label :country_id, "Country" %>
<%= f.collection_select :country_id, Country.order_by([:name, :asc]), :id, :name, include_blank: true %>

<%= f.label :state_id, "State or Province" %>
<%= f.grouped_collection_select :state_id, Country.order_by([:name, :asc]), :states, :name, :id, :name, include_blank: true %>

<% end %>

My issue is the :states appears to be empty. I know this because the html output is:

All the option values that should be within the option groups are not there.

I would appreciate any assistance anyone can give. Sorry for the lengthiness but i wanted to give all the details.

Cheers,

Rich