Nathan,
you''re not using "has_one" and "has_many" in the
way they''re intended.
A "has_one" is typically paired with a "belongs_to", where
the table
of the class specifying "belongs_to" contains the secondary key.
So in your case, you might write
class Rider < ActiveRecord::Base
has_one :ride
end
class Ride < ActiveRecord::Base
belongs_to :rider
end
With this setup, your db table "rides" would contain a field
"rider_id" (not "user_id"), which is your secondary key.
While the above will work, I don'' think it is what you really want --
unless you want to allow only a single rider for each ride... I prefer
riding in groups :) You should look up the "has_and_belongs_to_many"
association at http://ar.rubyonrails.com. (I''m assuming you mean ride
as in "trip", not ride as in "bike")
If you don''t have too many Rider instances, you could display a
checkbox for each existing Rider in your rides/new.rhtml, and
associate the selected Riders with the new Ride in your
RidesController#create method.
> <%= submit_tag "Create", :user_id => @user %>
This is not how submit_tag works. see
http://ap.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html
cheers
Gerret
>
> But from here I am entirely lost. How do I get the user_id to go into
> the ride table entry as a foreign key? It doesn''t do it now, after
> having setup the relationship.
>
> I am sure this is something simple, that I haven''t seen
demonstrated
> elsewhere yet. Any help is incredibly appreciated.
>
> Thanks!
> --
> Nathan Mealey
> Webmaster & Administrative Coordinator
> Cycle-Smart, Inc.
> P.O. Box 1482
> Northampton, MA
> 01061-1482
> nathan-mPKOtHdLgT0QaXB9iyTzyw@public.gmane.org
>
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>