Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blogger 2 - I3 Tagging, final step #1249

Open
mn113 opened this issue Aug 7, 2018 · 0 comments
Open

Blogger 2 - I3 Tagging, final step #1249

mn113 opened this issue Aug 7, 2018 · 0 comments

Comments

@mn113
Copy link

mn113 commented Aug 7, 2018

I'm not sure if this applies to Rails 5 or only an older version that the Blogger tutorial was created for.

Now that we can see all of our tags, we also want the capability to delete them. I think you can do this one on your own too. Create a destroy action in your tags_controller.rb and edit the index.html.erb file you just created. Look at your articles_controller.rb and Article show.html.erb if you need some clues.
With that, a long Iteration 3 is complete!

During this DIY step, a foreign key error was raised when I tried to delete a Tag the same way as taught for Articles.
ActiveRecord::InvalidForeignKey (SQLite3::ConstraintException: FOREIGN KEY constraint failed: DELETE FROM "tags" WHERE "tags"."id" = ?):

I solved it by (as on SO: https://stackoverflow.com/a/1905498) deleting the related Taggings first,

@tag = Tag.find(params[:id])
Tagging.where(tag_id: @tag.id).each{ |t| t.destroy }
@tag.destroy

but this is not even hinted at in the text, and ActiveRecord::QueryMethods#where hasn't been introduced at this stage.

Could one of the authors please give a Best Practice for deleting a tag without errors, and amend the tutorial text if necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant