Bruce Balmer
2005-Oct-27 21:13 UTC
Help. Problem with scaffolding and fields ending in _id
Hello: If I have a foreign key in a table, in the form tableName_id it will not show up in any views generated by the scaffold command. If I simply remove the _id from the end of the field, the fields shows up fine. I have spent 5 hours on this one problem and cannot find any reference to it anywhere on the web. I am very much hoping that someone can help me. I''ll be completely bald in another 5 hours. bruce
Jamie Macey
2005-Oct-27 21:16 UTC
Re: Help. Problem with scaffolding and fields ending in _id
On Thu, 2005-27-10 at 15:13 -0600, Bruce Balmer wrote:> Hello: > > If I have a foreign key in a table, in the form tableName_id it will > not show up in any views generated by the scaffold command. If I > simply remove the _id from the end of the field, the fields shows up > fine. > > I have spent 5 hours on this one problem and cannot find any > reference to it anywhere on the web. I am very much hoping that > someone can help me. I''ll be completely bald in another 5 hours. > > bruceBruce, Scaffolding isn''t smart enough to do any remote table associations yet. If you want to display or edit it, now is the time to start editing your scaffolding. - Jamie
Bruce Balmer
2005-Oct-27 21:28 UTC
Re: Help. Problem with scaffolding and fields ending in _id
Jamie: Thank you very much for writing. Could you help me one bit further since I''m still a bit confused? I read this on the web at address http://wiki.rubyonrails.com/rails/ pages/HowToExtendScaffolding Scaffolding is one of many great ideas that Rails has brought to the table, and is often the first “magic” feature that new users experience. However, by default, scaffolding does not deal with tables’ associations to each other. This is fairly limiting and makes using the default scaffold forms tedious. For example, let’s say you have two tables, albums and artists, with albums belonging to artists and each artists having many albums (with artist_id as the foreign key in the albums table). By default, the scaffolded new and edit forms for albums will display artist_id as a text input field, which is quite unhelpful if you don’t know the id of the artist by heart. What would be really nice is if you got a drop down select box of all artists, and you just picked one out of the list. Which indicates that it would show the associated fields. So are these people just talking out their behinds? I''m happy to get editing, I just need to know that it is necessary and I am not doing a whole lot of unnecessary work. I also don''t understand how rails knows not to display a table field ending in "_id". Is that deliberate? So just to make sure we are on the same page --- If i have two tables like so table people id int etc name & table preferences id int etc people_id int etc preference varchar(32) etc Then when I build the scaffolding for the ''preferences'' table I will only see the ''preference'' field and not the foreign key? On 27-Oct-05, at 3:16 PM, Jamie Macey wrote:> On Thu, 2005-27-10 at 15:13 -0600, Bruce Balmer wrote: > >> Hello: >> >> If I have a foreign key in a table, in the form tableName_id it will >> not show up in any views generated by the scaffold command. If I >> simply remove the _id from the end of the field, the fields shows up >> fine. >> >> I have spent 5 hours on this one problem and cannot find any >> reference to it anywhere on the web. I am very much hoping that >> someone can help me. I''ll be completely bald in another 5 hours. >> >> bruce >> > > Bruce, > > Scaffolding isn''t smart enough to do any remote table associations > yet. > If you want to display or edit it, now is the time to start editing > your > scaffolding. > > - Jamie > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
hkelsey-EcXoqBC4F/kd5Ot1ntKM6ZqQE7yCjDx5@public.gmane.org
2005-Oct-27 21:45 UTC
Re: Help. Problem with scaffolding and fields ending in _id
Bruce, Scaffolding show only content_columns() which is ''an array of column objects where the primary id, all columns ending in "_id" or "_count", and columns used for single table inheritance have been removed''. Time to start editing. Hugh Quoting Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org>:> Hello: > > If I have a foreign key in a table, in the form tableName_id it will > not show up in any views generated by the scaffold command. If I > simply remove the _id from the end of the field, the fields shows up > fine. > > I have spent 5 hours on this one problem and cannot find any > reference to it anywhere on the web. I am very much hoping that > someone can help me. I''ll be completely bald in another 5 hours. > > bruce > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
Bruce Balmer
2005-Oct-27 21:54 UTC
Re: Help. Problem with scaffolding and fields ending in _id
Hugh: That would explain it. Thank you. bruce On 27-Oct-05, at 3:45 PM, hkelsey-EcXoqBC4F/kd5Ot1ntKM6ZqQE7yCjDx5@public.gmane.org wrote:> Bruce, > > Scaffolding show only content_columns() which is ''an array of > column objects > where the primary id, all columns ending in "_id" or "_count", and > columns used > for single table inheritance have been removed''. Time to start > editing. > > Hugh > > Quoting Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org>: > > >> Hello: >> >> If I have a foreign key in a table, in the form tableName_id it will >> not show up in any views generated by the scaffold command. If I >> simply remove the _id from the end of the field, the fields shows up >> fine. >> >> I have spent 5 hours on this one problem and cannot find any >> reference to it anywhere on the web. I am very much hoping that >> someone can help me. I''ll be completely bald in another 5 hours. >> >> bruce >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > > > > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Jeremy Evans
2005-Oct-27 23:03 UTC
Re: Help. Problem with scaffolding and fields ending in _id
> Which indicates that it would show the associated fields. So are these > people just talking out their behinds?The information on that page is how to extend Rails scaffolding, which requires modifying the code that Rails uses to generate the scaffolding. You need to follow the instructions on the page to add that code to Rails, and configure your app appropriately. I''m not even sure if it works with versions greater than 0.13.1, as I haven''t tested it.> I''m happy to get editing, I just need to know that it is necessary and I am > not doing a whole lot of unnecessary work. I also don''t understand how > rails knows not to display a table field ending in "_id". Is that > deliberate?You can override this if you use the scaffolding extensions, by changing the @scaffold_fields array for the model.> Then when I build the scaffolding for the ''preferences'' table I will only > see the ''preference'' field and not the foreign key?Using the scaffolding extensions and @scaffold_fields = %w''person preference'' in your preference model, you''d get a drop down box with a list of people in addition to the text box for the preference.