I have two databases Tours and Bands such that:
- - begin code - -
class Band < ActiveRecord::Base
belongs_to :tours
end
class Tour < ActiveRecord::Base
has_one :bands
end
- - end code - -
In my admin_tours I have added a bit of code that gives me a drop down
menu with a selection of all bands in Bands:
- - begin code - -
<p><label for="band_id">Band</label><br>
<%= select("band", "band_id", Band.find_all.collect
{|p| [ p.name,
p.id ] }) %>
- - end code - -
Of course you imagine that I am looking to have band_id save when i save
tours. I am having a difficult time figuring out what code works I
should put in my ''admin_tours_controller''. As I have
scaffolded this out
so I am assuming I should be adding some sort of save code to
''update''
and ''create''.
I am willing to pay someone to walk me thru this (aim? tele?) or if you
have any quick (free) advice that would work too.
: )
thanks!
-----------------------
Mason Kessinger
-----------------------
http://www.poccuo.com
-----------------------
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
> - - begin code - - > > class Band < ActiveRecord::Base > belongs_to :tours > end > > class Tour < ActiveRecord::Base > has_one :bands > end >First, this should be has_one :band, not :bands> - - begin code - - > > <p><label for="band_id">Band</label><br> > <%= select("band", "band_id", Band.find_all.collect {|p| [ p.name, > p.id ] }) %> >I don''t know how did you built your DB schema, but it should be something like this ---- table bands: id name tour_id (other columns) table tours: id location (other columns) ---- in this case, when using belongs_to - has_one, the child element (aka the one who belongs to other) need to have a column indicating it''s association id (in my ex. it''s tour_id) that''s how you will get your relation. as for the select it''s should be <%= select_tag "tour", "band_id", Band.find(:all).collect {|e| [e.name, e.id]} %> if i missed your point, i''ll be happy to help you for free of course if you refer to my by mail (elad-JJg+wbmsuWCakBO8gow8eQ@public.gmane.org) or by MSN (eizesus-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org). hope this helps --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---