turbolinks_render icon indicating copy to clipboard operation
turbolinks_render copied to clipboard

Rails UJS tries to execute response as JavaScript, gets blocked by CSP

Open vitobotta opened this issue 4 years ago • 0 comments

Hi! I am trying to use this gem but can't get it to work. I'm on Rails 6, and it seems that something in Rails UJS interferes because the content type is text/javascript and therefore it tries to add a script tag to the page:

document.head.appendChild(script).parentNode.removeChild(script);

I have simply added the gem, and the create action is like this:

  def create
    @blog = current_user.blogs.new(create_blog_params)
    authorize @blog

    respond_to do |format|
      if @blog.save
        format.html { redirect_to @blog }
      else
        format.html { render :new }
      end
    end
  end

The form is like this:

<%= form_with model: @blog, html: { novalidate: "novalidate" }, class: "form max-w-2xl p-8" do |f

What am I missing?

Thanks in advance!

vitobotta avatar Apr 22 '20 15:04 vitobotta