I''m sure I''m overlooking something really obvious, but
I''m trying to
figure out how to do a form for an object associated with the current
view object.
Specifically, I have an itinerary that has events. When I''m looking at
an itinerary I should be able to add new events. My relationship
between the two is:
class Itinerary < ActiveRecord::Base
has_many :event
end
class Event < ActiveRecord::Base
has_one :itinerary
end
In the itineraries_controller, I have a show method defined like this:
def show
@itinerary = Itinerary.find(params[:id])
@new_event = Event.new
end
However, it is clearly puking on the Event.new, and I''m looking for a
good place to learn about how to work through all of these
associations. If this isn''t the place, I''d love a link to
where this
is taught.
Thanks in advance.
--
Melih O.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
So I''ve updated my show method to look like:
def show
@itinerary = Itinerary.find(params[:id])
@new_event = @itinerary.events.build
end
but still no luck.
Thanks again.
--
Melih O.
On May 22, 8:21 pm, Melih Onvural
<melih.onvu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I''m sure I''m overlooking something really obvious, but
I''m trying to
> figure out how to do a form for an object associated with the current
> view object.
>
> Specifically, I have an itinerary that has events. When I''m
looking at
> an itinerary I should be able to add new events. My relationship
> between the two is:
>
> class Itinerary < ActiveRecord::Base
> has_many :event
> end
>
> class Event < ActiveRecord::Base
> has_one :itinerary
> end
>
> In the itineraries_controller, I have a show method defined like this:
>
> def show
> @itinerary = Itinerary.find(params[:id])
>
> @new_event = Event.new
> end
>
> However, it is clearly puking on the Event.new, and I''m looking
for a
> good place to learn about how to work through all of these
> associations. If this isn''t the place, I''d love a link to
where this
> is taught.
>
> Thanks in advance.
> --
> Melih O.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Got it. I had a has_one relationship where I needed a belongs_to relationship. Thanks interwebs :-) -- Melih On May 22, 9:22 pm, Melih Onvural <melih.onvu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So I''ve updated my show method to look like: > > def show > @itinerary = Itinerary.find(params[:id]) > @new_event = @itinerary.events.build > end > > but still no luck. > > Thanks again. > -- > Melih O. > > On May 22, 8:21 pm, Melih Onvural <melih.onvu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m sure I''m overlooking something really obvious, but I''m trying to > > figure out how to do a form for an object associated with the current > > view object. > > > Specifically, I have an itinerary that has events. When I''m looking at > > an itinerary I should be able to add new events. My relationship > > between the two is: > > > class Itinerary < ActiveRecord::Base > > has_many :event > > end > > > class Event < ActiveRecord::Base > > has_one :itinerary > > end > > > In the itineraries_controller, I have a show method defined like this: > > > def show > > @itinerary = Itinerary.find(params[:id]) > > > @new_event = Event.new > > end > > > However, it is clearly puking on the Event.new, and I''m looking for a > > good place to learn about how to work through all of these > > associations. If this isn''t the place, I''d love a link to where this > > is taught. > > > Thanks in advance. > > -- > > Melih O.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.