Table associations

I have 2 tables


cursos
id
name


turmas
id
cursos_id
name

Model turma

belongs_to :cursos

Model curso

has_manay :turma

TurmasController
scaffold:turma

Ok, it’s works, but I can’t select, the Curso in curso ID field,
it’s only display the field name…

what can be wrong?

On 6/28/06, Fernando [email protected] wrote:

cursos_id
has_manay :turma
has_many :turmas

not working yeat

Table Cursos
id
name

Table Turmas
id
name
cursos_id

Model Turma
class Turma < ActiveRecord::Base
belongs_to :cursos
end

Model Curso
class Curso < ActiveRecord::Base
has_many :turmas
end

turmas_controller
class TurmasController < ApplicationController
scaffold:turma
end

When I click in the link NEW TURMA
the form display only 1 field…

the name field.

And my Cursos Table is not empty.

I’ve come in late to this discussion, so I haven’t seen what messages
have already been sent back and forth. Sorry if I’m going to cover
anything that’s already been brought up…

On Jun 28, 2006, at 12:26 PM, Fernando wrote:

cursos_id

And my Cursos Table is not empty.

What you are seeing is not an unexpected result. Unfortunately, you
are using the scaffold controller method, and not a fully generated
scaffold, from a call to:

./script/generate scaffold Turma

If you were to generate the scaffold, you would see that when the new
(also the edit) form is built that it only contains entry fields for
those columns that a user would normally enter data into. Rails calls
these the “content columns” of a given ActiveRecord model class. ID
columns, whether they are primary key fields (ie. id) , or foreign
key fields (ie. cursos_id) are not considered content columns by
Active Record.

Additionally, the built in scaffolding is only for building a basic
CRUD structure for a single model class. There are no facilities,
though the build-in scaffolding, to do anything with associated tables.

This is why what you are seeing is, in fact, what you are supposed to
be seeing.

-Brian

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs