0
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>**
在型號:NoMethodError:未定義的方法`每個」爲#<國家:0x438a110>
class State < ActiveRecord::Base
belongs_to :country
class Country < ActiveRecord::Base
has_many :states
我在新的軌道。我想設置成COUNTRY_ID它的狀態,但它給我的錯誤。我認爲我做了一切正確的事,但仍然發生這種錯誤。請幫助我。
感謝兄弟@SLD – Jack 2014-10-04 03:16:48