gary.huntress-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-07 03:21 UTC
Scaffolds, Multiple Tables, and Key Fields
Is there a simple way to edit two tables with a has_many/belongs_to relationship? I have a very typical parent table (Departments) with an id, name, description, etc. And I have a child Resources table with an id, department_id, title, description, and other fields. I want to allow a user to edit the child table but I see that the standard behavior for scaffolds is to suppress displaying key fields (primary and foreign) is there a way to override this? Basically when I''m editing the child record I really need to display the Department.title. I know I can do this by hand, but I''d like the scaffolding to help me if possible! is it? Thanks, Gary H. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Check out the 3-part screencast on complex forms at railscasts.com starting with #73 http://railscasts.com/episodes/73 This will walk you through setting up editing two forms at once if you want something more complex. On Dec 6, 9:21 pm, "gary.huntr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <gary.huntr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Basically when I''m editing the child record I really need to display > the Department.title. I know I can do this by hand, but I''d like > the scaffolding to help me if possible! is it?I don''t know of a way for Scaffold to do it, possibly ActiveScaffold would. http://activescaffold.com/ or just In your Resources (that''s the child right?) view, use this in your _form <%= collection_select :resource, :department_id, Department.find(:all), :id, :name %> Read more about collection_select here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000928 it puts in department_id of a resource from what was collected from all department listings and give you a select field with id of department as a value and name of department as text. and in your list use <%= resource.department.name %> inside the for statement, and in show <%= @resource.department.name %> anywhere. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---