dangerwillrobinsondanger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-06 03:36 UTC
want to show content of foreign key in rhtml-- Newbie
Hi I have a scaffold CRUD app going and have managed to get my foreign key to populate a select dropdown list in the edit/new _form.rhtml It seemed logical to have a foreign key with a select list. Unfortunately, I can''t figure out how to get the content of that same foreign key to appear in show or list actions. My tables are: artworks categories In the artworks table there is a column named category_id and it belongs_to :category, :foreign_key => ''category_name'' In the categories table there is a column named category_name Any tips or help here? Do I need to do something in my category.rb or artwork.rb models? or in my admin_controller.rb controller? The default scaffold template show.rhtml uses: for columns in Artwork.content_columns (I''m assuming this is the same as: Artwork.content_columns.each do |column| ... end ) I checked out the content_columns method in the API and says that it strips out an array item that ends with _id but that seems to be the logical choice for a foreign key! So, if I change the schema to use a different name for the foreign key, will it work? Or am I way lost. (I feel lost) Please be gentle and verbose! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dangerwillrobinsondanger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-06 20:51 UTC
Re: want to show content of foreign key in rhtml-- Newbie
Wow, this is a pretty unresponsive list here. I''m glad Ruby-Talk is not like this. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 5, 8:36 pm, "dangerwillrobinsondan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <dangerwillrobinsondan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi I have a scaffold CRUD app going and have managed to get my foreign > key to populate a select dropdown list in the edit/new _form.rhtml > It seemed logical to have a foreign key with a select list. > Unfortunately, I can''t figure out how to get the content of that same > foreign key to appear in show or list actions. > > My tables are: > > artworks > > categories > > In the artworks table there is a column named category_id and it > belongs_to :category, :foreign_key => ''category_name''I think category_id is your foreign key there, just delete the foreign_key arg... you don''t need it at all since AR will default to category_id in this case... and I suspect it is causing you trouble.> > In the categories table there is a column named category_name > > Any tips or help here? Do I need to do something in my category.rb or > artwork.rb models? or in my admin_controller.rb controller?don''t think so> > The default scaffold template show.rhtml uses: > for columns in Artwork.content_columns > > (I''m assuming this is the same as: > Artwork.content_columns.each do |column| ... end )They''re actually not exactly the same, the variables are scoped differently but in this instance they likely work the same.> > I checked out the content_columns method in the API and says that it > strips out an array item that ends with _id but that seems to be the > logical choice for a foreign key! > So, if I change the schema to use a different name for the foreign > key, will it work? Or am I way lost. (I feel lost) > > Please be gentle and verbose!try using column_names (Artwork.column_names) instead. good luck! Tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dangerwillrobinsondanger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-08 17:21 UTC
Re: want to show content of foreign key in rhtml-- Newbie
Thanks for the help. I found my answers by working through the tutorial at OnLamp. It answered my questions while being simple and focused enough to prevent other things compounding my questions. The Agile book has a lot in it, but the tutorial there is just a little too kitchen-sink to grasp some aspects well. Turns out, there were indeed some automagic naming conventions I should have used, but didn''t and that threw me off. Rails is certainly different from many Ruby programs. I''m starting to see that Rails does more for me if I do a lot more the way it expects things. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---