Is there any reason that foreign key fields do not show in any of the scaffold views ? project table: id serial primary key, category_id integer, user_id integer, name varchar, morestuff varchar foreign key (category_id) references categories(id), foreign key (user_id) references users(id) scaffold generated views only show name, morestuff fields
John: I don''t know the reason, but if it puts your mind at rest, you are doing nothing wrong. This is the way it is with scaffolding. It is very easy to add foreign key fields to the existing scaffolding. Just follow the pattern laid out by the fields that are there and use something like collection_select to get a drop down to work with the linked tables. bruce On 12-Jan-06, at 11:22 PM, John Taber wrote:> Is there any reason that foreign key fields do not show in any of > the scaffold views ? > > project table: > id serial primary key, > category_id integer, > user_id integer, > name varchar, > morestuff varchar > foreign key (category_id) references categories(id), > foreign key (user_id) references users(id) > > scaffold generated views only show name, morestuff fields > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Rube Goldberg
2006-Jan-13 16:51 UTC
[Rails] Re: missing foreign key fields in scaffold views
John John wrote:> Is there any reason that foreign key fields do not show in any of the > scaffold views ? > > project table: > id serial primary key, > category_id integer, > user_id integer, > name varchar, > morestuff varchar > foreign key (category_id) references categories(id), > foreign key (user_id) references users(id) > > scaffold generated views only show name, morestuff fields>From what I read, scaffold causes rails to hide anything named id orending with _id. If you want, say, dropdown menus from lookup tables ( I needed these. Took a long time to figure out how to do ) try this: <%= options_from_collection_for_select(Yourmodel.find(:all, :order => "id"), :id, :lookupField, selected_value= someIDhere) %></select> someIDhere in my cases was the foreign key field in the parent table. This allowed me to get it to select the right entry for that record. options_from_collection_for_select is in the rails API. You''ll be spending a LOT of time sifting through that if you plan to stick it out in rails. Good luck. -- Posted via http://www.ruby-forum.com/.
On 1/12/06, John Taber <jtaber@johntaber.net> wrote:> Is there any reason that foreign key fields do not show in any of the > scaffold views ? > > project table: > id serial primary key, > category_id integer, > user_id integer, > name varchar, > morestuff varchar > foreign key (category_id) references categories(id), > foreign key (user_id) references users(id) > > scaffold generated views only show name, morestuff fieldsIf you want the user and category for the project scaffolded with a select box, you can look into the Scaffolding Extensions plugin.
Thank you. It would be helpful if someone could write an article on all the Rails extras that are available - I think some of us are missing out on a lot of features. Jeremy Evans wrote:> On 1/12/06, John Taber <jtaber@johntaber.net> wrote: > >>Is there any reason that foreign key fields do not show in any of the >>scaffold views ? >> >>project table: >>id serial primary key, >>category_id integer, >>user_id integer, >>name varchar, >>morestuff varchar >>foreign key (category_id) references categories(id), >>foreign key (user_id) references users(id) >> >>scaffold generated views only show name, morestuff fields > > > If you want the user and category for the project scaffolded with a > select box, you can look into the Scaffolding Extensions plugin. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >