Question: ```
 1.  country=Country.create(:name=>'Australia')
 2.  country.states
    #<ActiveRecord::Associations::CollectionProxy []>

 3. first_state=State.new(:name=>'Queensland')
=> #<State id: nil, country_id: nil, name: "Queensland", created_at: nil, update
d_at: nil>
 4. first_state.country
=> nil

 5.country.states=first_state

**NoMethodError: undefined method `each' for #<State:0x438a110>**

```

In Model:

```
class State < ActiveRecord::Base
  belongs_to :country

class Country < ActiveRecord::Base
  has_many :states

```

I am new in rails. I am trying to set country\_id into it's state, but it give me error. I have done everything right I think, but still this error occurs. Please help me out.

Answer: 
It's state**s** (plural); it's expecting an array

```
country.states = [first_state]

```
Or you could push to the states array like

```
country.states<< first_state

```

Additionally, since you are using constant tables, you could use [this](https://github.com/Codebrahma/constantizable) gem to query them. Also please feel free to contribute to the gem if you like it.