Jeremy Evans
2005-Jul-18 20:30 UTC
RE: hide ''id'' field in ''edit'' view again (afterHowToExtendScaffolding)?
> After following the instructions on > http://wiki.rubyonrails.com/rails/show/HowToExtendScaffolding there appears > an ''id'' edit field on my edit webpaqes. Since this is the primary key of the >table, I really don''t want a user to be able to edit it :)Make sure that @scaffold_fields is defined for the model and that it does not include "id". If you don''t define it, the extended scaffolding uses all columns that are in the database. See the example on that page: class Album < ActiveRecord::Base belongs_to :artist @scaffold_fields = %w''artist name releasedate rating'' end ***************************************************************** * Confidentiality Notice: This e-mail message, including any * * attachments, is for the sole use of the intended recipient(s) * * and may contain confidential and privileged information, * * including information pertaining to an ongoing audit or * * investigation (see Cal. Gov. C. Secs. 8545, 8545.1 and * * 8547). Any unauthorized review, use, disclosure, or * * distribution is prohibited. If you are not the intended * * recipient, please contact the sender by reply e-mail and * * destroy all copies of the original message. * *****************************************************************
Jeroen Janssen
2005-Jul-19 06:41 UTC
RE: hide ''id'' field in ''edit'' view again(afterHowToExtendScaffolding)?
> [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] Namens Jeremy Evans > > After following the instructions on > > > http://wiki.rubyonrails.com/rails/show/HowToExtendScaffolding there > > appears > an ''id'' edit field on my edit webpaqes. Since this is the > > primary key of the >table, I really don''t want a user to be able to > > edit it :) > Make sure that @scaffold_fields is defined for the model and > that it does not include "id". If you don''t define it, the > extended scaffolding uses all columns that are in the > database. See the example on that page: > class Album < ActiveRecord::Base belongs_to :artist > @scaffold_fields = %w''artist name releasedate rating'' endThanks! That solved my problem. Now I also know what I did wrong too. I was being ''clever'' and did : @scaffold_fields = column_names - %w''location_id'' + %w''location'' Where location_id refers to :locations. I did this because I didn''t want to hardcode the other fields of my webpage, but after reading your comments I understand ''id'' is being present in column_names. So now I did the following: @scaffold_fields = column_names - %w''location_id id'' + %w''location'' And it works ok. However, I am left with some other questions: * I assume that the create scaffold page knows itself about id and as a result doesn''t show it (regardless whether id is present in @scaffold_fields)? * I have to change location_id and location in @scaffold_fields, I imagine that this knowledge can also be build in the HowToExtendScaffolding code)? --- Jeroen Janssen