Ruby on Rails Friday, May 31, 2013

Hi,

I'm learning rails and have run into what for me is a difficult problem.
I have the following associations with a galleries_pictures and a
pictures_questions join table:

class Picture < ActiveRecord::Base
has_and_belongs_to_many :questions
has_and_belongs_to_many :galleries

class Question < ActiveRecord::Base
has_and_belongs_to_many :pictures

class Gallery < ActiveRecord::Base
has_and_belongs_to_many :pictures

In the edit question view, a question and its associated picture(s) can
be edited. My problem is, I cannot figure out how to delete the picture
in the question and at the same time not delete it from the gallery ie
delete the pictures_questions association but not the
galleries_pictures association.

The action called from the view deletes the row in both join tables:
def destroy
@picture = Picture.find(params[:id])
@picture.destroy

Thanks!

--
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/40e6e1ce0974b1d11da257d0402b29eb%40ruby-forum.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment