Sunday, May 27, 2012

Re: [Rails] How to load a selection list into the method new of a controller?

On 28 May 2012 04:37, LuisRuby <alfamemoria@gmail.com> wrote:
> Hi friends!
> I'm relatively new with Rails and I'm struggling for a long time with this
> problem (it should have a pattern solution but until now I didn't find it):
> I have the following models: Institution, City, State and Country.
>
> class Country < ActiveRecord::Base
>   has_many :states
>   has_many :cities, :through => :states
> end
> # == Schema Information
> # Table name: countries
> #  id         :integer         not null, primary key
> #  sigla      :string(2)       not null
> #  nome       :string(30)      not null
>
> class State < ActiveRecord::Base
>   has_many   :cities
>   has_many   :institutions, :through => :cities
>   belongs_to :country
> end
> # == Schema Information
> # Table name: states
> #  id         :integer         not null, primary key
> #  country_id :integer     not null
> #  sigla      :string(2)      not null
> #  nome       :string(40)  not null
>
> class City < ActiveRecord::Base
>   has_many :institutions
>   belongs_to :country

That is not right, a cities country is accessible through the state
via @city.state.country.

>   belongs_to :state
> end
> # == Schema Information
> # Table name: cities
> #  id          :integer         not null, primary key
> #  country_id  :integer         not null

Above is not needed.

I have not even read the rest, you have provided much too much
information. If you still have a problem then simplify it down to to
the smallest amount of code that demonstrates it and post that.

Colin

> #  state_id    :integer         not null
> #  nome        :string(40)      not null

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate