ga-wdi-exercises / project2

[project]
1 stars 30 forks source link

issue with join table #915

Closed dionadk closed 6 years ago

dionadk commented 7 years ago

I am using a join table to tag a tag name to a picture uploaded. Currently i can add a pic and create a tag name for the pic. but not getting how to tag the pic to the tag name created(join table - tagging is supposed to link the tag id and pic id.). So that i can see all the tag name created for that pic.

link to my github repo: https://github.com/dionadk/Wexels

aspittel commented 6 years ago

I would create a form associated with the picture at a given route pictures/8/add_tag.

That will be a form with all the possible tags listed out (like this https://github.com/ga-wdi-exercises/rails-many-to-many-lab/blob/solution/app/views/appointments/_form.html.erb).

Then the user presses save which will create relationships between all of the saved ones -- which should just look like a normal update like this: https://github.com/ga-wdi-exercises/rails-many-to-many-lab/blob/solution/app/controllers/appointments_controller.rb.

This would be the easiest way -- you could also have that form embedded on the show page you have now using similar steps.

dionadk commented 6 years ago

I tried doing. Can you please take a look at my routes?. Im not able to get a path like pics/1/add_tag added a tagging controller and forms

link to my github repo: https://github.com/dionadk/Wexels

superbuggy commented 6 years ago

What does rails routes output?

Also, a note:

In /app/controllers/tags_controller.rb...

  def show
    @tag = Tag.find(params[:id])
    @taggings = Tagging.joins(:tag, :pic) #.joins is for performing a join query
  end
  def show
    @tag = Tag.find(params[:id])
-   @taggings = Tagging.joins(:tag, :pic)
+   @tag.taggings
  end
dionadk commented 6 years ago

I am getting an error - when i try adding a new tag No route matches [GET] "/pics/2/add_tagging"

My routes output.......

root GET / pics#index pic_comments GET /pics/:pic_id/comments(.:format) comments#index POST /pics/:pic_id/comments(.:format) comments#create new_pic_comment GET /pics/:pic_id/comments/new(.:format) comments#new edit_pic_comment GET /pics/:pic_id/comments/:id/edit(.:format) comments#edit pic_comment GET /pics/:pic_id/comments/:id(.:format) comments#show PATCH /pics/:pic_id/comments/:id(.:format) comments#update PUT /pics/:pic_id/comments/:id(.:format) comments#update DELETE /pics/:pic_id/comments/:id(.:format) comments#destroy add_tagging_pic POST /pics/:id/add_tagging(.:format) pics#add_tagging pics GET /pics(.:format) pics#index POST /pics(.:format) pics#create new_pic GET /pics/new(.:format) pics#new edit_pic GET /pics/:id/edit(.:format) pics#edit pic GET /pics/:id(.:format) pics#show PATCH /pics/:id(.:format) pics#update PUT /pics/:id(.:format) pics#update DELETE /pics/:id(.:format) pics#destroy tags GET /tags(.:format) tags#index POST /tags(.:format) tags#create new_tag GET /tags/new(.:format) tags#new edit_tag GET /tags/:id/edit(.:format) tags#edit tag GET /tags/:id(.:format) tags#show PATCH /tags/:id(.:format) tags#update PUT /tags/:id(.:format) tags#update DELETE /tags/:id(.:format) tags#destroy

superbuggy commented 6 years ago

This resource should be valuable!

https://hackhands.com/building-has_many-model-relationship-form-cocoon/

superbuggy commented 6 years ago

closing for now!