Skip to main content

Nested Comment Threads in Rails - Part 3 Discussion

General • Asked by Chris Oliver

Really great series, thank you for doing it. One question:
I have a comment form below the comments and it is not clearing out. However, when I move above the comments it does. Any thoughts?

Really great series, thank you for doing it. One question:

I have a comment form below the comments and it is not clearing out once the comment is posted. However, when I move the form above the comments (as shown in the tutorial) it does clear the form. Any thoughts?


Rails 5.2.1 comes with Content Security Policy DSL by default. Here we can specificy what is allowed to run. If we have something like

Rails.application.config.content_security_policy do |policy|
  policy.default_src :self, :https
  policy.connect_src :self
  #...
  policy.script_src  :self
end

# If you are using UJS then enable automatic nonce generation
Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }

in our CSP file I think this would disallow everything in create.js.erb ? We could add unsafe_eval to the policy but I believe this negates the whole purpose.

What can we add to allow the create.js.erb to be allowed by the Content Security Policy? I tried adding the <%= csp_meta_tag %> as recommeded here https://edgeguides.rubyonrails.org/security.html#content-security-policy and mentioned here https://github.com/rails/rails/pull/32018. Am I understanding the architecture correctly?


Hi Chris - great tutorial. Is this methodology what you would recommend if you are adding comments to a new site? I know there are gems out there that build this in automatically. Also, what about Vue.js - do you think using Ajax in this way is preferable to building out some Vue.js component.


Great tutorial.

Unfortunately, this breaks the max_nesting from the last episode :/


Hey Chris, just following up on Jake's comment. I'm also having the issue where max_nesting no longer works after implementing ajax following this video (the comments keep nesting past the max_nesting depth). Any idea what's causing this to break or how to fix it?

This series has been very helpful. Thanks so much!


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.