title: Rails 6, js.erb files not loading
body: <p>I'm doing on a blog tutorial from youtube and it was working really well until I get to the part where he has an update.js.erb file that is supposed to load when updating an element on the past.  When I edit the element and click save, I get the following error:</p>
  <pre><code>ActionController::UnknownFormat (Authors::ElementsController#update is missing a template for this request format and variant.
  
  request.formats: [&quot;text/html&quot;]
  request.variant: []):
    
  actionpack (6.1.3) lib/action_controller/metal/implicit_render.rb:42:in `default_render'
  actionpack (6.1.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
  &lt;internal:kernel&gt;:90:in `tap'
  actionpack (6.1.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
  actionpack (6.1.3) lib/abstract_controller/base.rb:228:in `process_action'
  actionpack (6.1.3) lib/action_controller/metal/rendering.rb:30:in `process_action'
  actionpack (6.1.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
  activesupport (6.1.3) lib/active_support/callbacks.rb:117:in `block in run_callbacks'
  actiontext (6.1.3) lib/action_text/rendering.rb:20:in `with_renderer'
  actiontext (6.1.3) lib/action_text/engine.rb:55:in `block (4 levels) in &lt;class:Engine&gt;'
  activesupport (6.1.3) lib/active_support/callbacks.rb:126:in `instance_exec'
  activesupport (6.1.3) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
  activesupport (6.1.3) lib/active_support/callbacks.rb:137:in `run_callbacks'
  actionpack (6.1.3) lib/abstract_controller/callbacks.rb:41:in `process_action'
  actionpack (6.1.3) lib/action_controller/metal/rescue.rb:22:in `process_action'
  actionpack (6.1.3) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
  activesupport (6.1.3) lib/active_support/notifications.rb:203:in `block in instrument'
  activesupport (6.1.3) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
  activesupport (6.1.3) lib/active_support/notifications.rb:203:in `instrument'
  actionpack (6.1.3) lib/action_controller/metal/instrumentation.rb:33:in `process_action'
  actionpack (6.1.3) lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
  activerecord (6.1.3) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
  actionpack (6.1.3) lib/abstract_controller/base.rb:165:in `process'
  actionview (6.1.3) lib/action_view/rendering.rb:39:in `process'
  actionpack (6.1.3) lib/action_controller/metal.rb:190:in `dispatch'
  actionpack (6.1.3) lib/action_controller/metal.rb:254:in `dispatch'
  actionpack (6.1.3) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
  actionpack (6.1.3) lib/action_dispatch/routing/route_set.rb:33:in `serve'
  actionpack (6.1.3) lib/action_dispatch/journey/router.rb:50:in `block in serve'
  actionpack (6.1.3) lib/action_dispatch/journey/router.rb:32:in `each'
  actionpack (6.1.3) lib/action_dispatch/journey/router.rb:32:in `serve'
  actionpack (6.1.3) lib/action_dispatch/routing/route_set.rb:842:in `call'
  warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
  warden (1.2.9) lib/warden/manager.rb:34:in `catch'
  warden (1.2.9) lib/warden/manager.rb:34:in `call'
  rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
  rack (2.2.3) lib/rack/etag.rb:27:in `call'
  rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'
  rack (2.2.3) lib/rack/head.rb:12:in `call'
  actionpack (6.1.3) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
  actionpack (6.1.3) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
  rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
  rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/cookies.rb:689:in `call'
  activerecord (6.1.3) lib/active_record/migration.rb:601:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
  activesupport (6.1.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
  actionpack (6.1.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
  web-console (4.1.0) lib/web_console/middleware.rb:132:in `call_app'
  web-console (4.1.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (4.1.0) lib/web_console/middleware.rb:17:in `catch'
  web-console (4.1.0) lib/web_console/middleware.rb:17:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
  railties (6.1.3) lib/rails/rack/logger.rb:37:in `call_app'
  railties (6.1.3) lib/rails/rack/logger.rb:26:in `block in call'
  activesupport (6.1.3) lib/active_support/tagged_logging.rb:99:in `block in tagged'
  activesupport (6.1.3) lib/active_support/tagged_logging.rb:37:in `tagged'
  activesupport (6.1.3) lib/active_support/tagged_logging.rb:99:in `tagged'
  railties (6.1.3) lib/rails/rack/logger.rb:26:in `call'
  sprockets-rails (3.2.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/request_id.rb:26:in `call'
  rack (2.2.3) lib/rack/method_override.rb:24:in `call'
  rack (2.2.3) lib/rack/runtime.rb:22:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/static.rb:24:in `call'
  rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
  actionpack (6.1.3) lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
  webpacker (5.2.1) lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
  rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
  railties (6.1.3) lib/rails/engine.rb:539:in `call'
  puma (5.2.1) lib/puma/configuration.rb:247:in `call'
  puma (5.2.1) lib/puma/request.rb:76:in `block in handle_request'
  puma (5.2.1) lib/puma/thread_pool.rb:337:in `with_force_shutdown'
  puma (5.2.1) lib/puma/request.rb:75:in `handle_request'
  puma (5.2.1) lib/puma/server.rb:431:in `process_client'
  puma (5.2.1) lib/puma/thread_pool.rb:145:in `block in spawn_thread'
  
  </code></pre>
  <p>The edit.html.erb file is:</p>
  <pre><code>&lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;col-md-4&quot;&gt;
      &lt;%= link_to 'Back', posts_path, class: 'btn btn-dark mb-3' %&gt;
      &lt;div class=&quot;card&quot;&gt;
        &lt;div class=&quot;card-header&quot;&gt;
          &lt;h6 class='card-title mb-0'&gt;Editing Post&lt;/h6&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-body&quot;&gt;
          &lt;%= render 'form', post: @post %&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-footer&quot;&gt;
          &lt;% if @post.published? %&gt;
            &lt;a href=&quot;#&quot;
              class='btn btn-secondary btn-block'
              data-reflex='click-&gt;PublisherReflex#unpublish'
              data-post-id='&lt;%= @post.id %&gt;'&gt;
              Unpublish
            &lt;/a&gt;
          &lt;% else %&gt;
            &lt;a href=&quot;#&quot;
              class='btn btn-dark btn-block'
              data-reflex='click-&gt;PublisherReflex#publish'
              data-post-id='&lt;%= @post.id %&gt;'&gt;
              Publish
            &lt;/a&gt;
          &lt;% end %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col-md-8&quot;&gt;
      &lt;div class=&quot;mb-3&quot;&gt;
        &lt;%= form_with(model: [@post, @element], html: { class: 'float-left mr-1' }) do |form| %&gt;
          &lt;%= form.hidden_field :element_type, value: 'paragraph' %&gt;
          &lt;%= button_tag(type: 'submit', class: 'btn btn-secondary') do %&gt;
            &lt;i class=&quot;fas fa-paragraph&quot;&gt;&lt;/i&gt;
          &lt;% end %&gt;
        &lt;% end %&gt;
        &lt;%= form_with(model: [@post, @element]) do |form| %&gt;
          &lt;%= form.hidden_field :element_type, value: 'image' %&gt;
          &lt;%= button_tag(type: 'submit', class: 'btn btn-secondary') do %&gt;
            &lt;i class=&quot;fas fa-image&quot;&gt;&lt;/i&gt;
          &lt;% end %&gt;
        &lt;% end %&gt;
      &lt;/div&gt;
      &lt;div class=&quot;card mb-5&quot;&gt;
        &lt;div class=&quot;card-header text-right&quot;&gt;
          &lt;% if @post.published? %&gt;
            &lt;b&gt;Published&lt;/b&gt; &lt;%= time_ago_in_words(@post.published_at) %&gt; ago
          &lt;% else %&gt;
            Unpublished
          &lt;% end %&gt;
        &lt;/div&gt;
  
        &lt;div class=&quot;card-body pt-5&quot; data-controller=&quot;elements&quot;&gt;
          &lt;% if @post.elements.none? { |element| element.persisted? } %&gt;
            &lt;div class=&quot;p-4 text-center&quot;&gt;
              &lt;h2 class='text-secondary'&gt;
                &lt;i class=&quot;fas fa-lightbulb&quot;&gt;&lt;/i&gt;
              &lt;/h2&gt;
              &lt;p&gt;Click the icons above to add elements to this post.&lt;/p&gt;
            &lt;/div&gt;
          &lt;% else %&gt;
            &lt;ul id='elements' data-action=&quot;drop-&gt;elements#sort&quot;&gt;
              &lt;% @post.elements.order(position: :asc).each do |element| %&gt;
                &lt;% if element.persisted? %&gt;
                  &lt;li data-id=&quot;&lt;%= element.id %&gt;&quot; class='element-item'&gt;
                    &lt;% if element.paragraph? %&gt;
                      &lt;div class=&quot;mb-4 p-3 paragraph&quot;&gt;
                        &lt;div class=&quot;paragraph-content&quot;&gt;
                          &lt;% if element.content.present? %&gt;
                            &lt;%= element.content %&gt;
                          &lt;% else %&gt;
                            Click to add content.
                          &lt;% end %&gt;
                        &lt;/div&gt;
                        &lt;div class=&quot;paragraph-form d-none&quot; id='element-&lt;%= element.id %&gt;-form'&gt;
                          &lt;%= form_with(model: [@post, element]) do |form| %&gt;
                            &lt;%= form.rich_text_area :content, id: &quot;element_content_#{element.id}&quot; %&gt;
                            &lt;div class=&quot;mt-3 d-flex justify-content-between&quot;&gt;
                              &lt;div&gt;
                                &lt;%= form.submit &quot;Save&quot;, class: 'btn btn-primary' %&gt;
                                &lt;a href=&quot;#&quot; class='cancel btn btn-secondary'&gt;Cancel&lt;/a&gt;
                              &lt;/div&gt;
                              &lt;%= link_to 'Delete', post_element_path(@post, element), method: :delete, class: 'btn btn-danger', data: { confirm: &quot;Are you sure?&quot; } %&gt;
                            &lt;/div&gt;
                          &lt;% end %&gt;
                        &lt;/div&gt;
                      &lt;/div&gt;
                    &lt;% elsif element.image? %&gt;
                      &lt;div class=&quot;mb-4 p-3 image&quot;&gt;
                        &lt;% if element.image.present? %&gt;
                          &lt;%= link_to post_element_path(@post, element), method: :delete, class: 'delete-btn btn btn-dark mt-2 float-right', data: { confirm: &quot;Are you sure?&quot; } do %&gt;
                            &lt;i class='fas fa-times'&gt;&lt;/i&gt;
                          &lt;% end %&gt;
                          &lt;%= image_tag(element.image) %&gt;
                        &lt;% else %&gt;
                          &lt;%= form_with(model: [@post, element]) do |form| %&gt;
                            &lt;%= form.file_field :image %&gt;
                            &lt;div class=&quot;mt-3&quot;&gt;
                              &lt;%= form.submit &quot;Save&quot;, class: 'btn btn-primary' %&gt;
                              &lt;a href=&quot;#&quot; class='cancel btn btn-secondary'&gt;Cancel&lt;/a&gt;
                            &lt;/div&gt;
                          &lt;% end %&gt;
                        &lt;% end %&gt;
                      &lt;/div&gt;
                    &lt;% end %&gt;
                  &lt;% end %&gt;
                &lt;/li&gt;
              &lt;% end %&gt;
            &lt;/ul&gt;
          &lt;% end %&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>The update.js.erb file is:</p>
  <pre><code>var element = document.getElementById('element-&lt;%= @element.id %&gt;-form')
  
  element.classList.add('d-none')
  element.previousElementSibling.classList.remove('d-none')
  
  var html = &quot;&lt;div class='trix-content'&gt;&lt;%= @element.content.body.html_safe %&gt;&lt;/div&gt;&quot;
  
  element.previousElementSibling.innerHTML = html
  </code></pre>
  <p>And the elements controller:</p>
  <pre><code>module Authors
    class ElementsController &lt; AuthorsController
      before_action :set_post
      before_action :set_element, only: [:update, :destroy]
  
      # POST /elements
      def create
        @element = @post.elements.build(element_params)
  
        if @element.save
          notice = nil
        else
          notice = @element.errors.full_messages.join(&quot;. &quot;) &lt;&lt; &quot;.&quot;
        end
        redirect_to edit_post_path(@post), notice: notice
      end
  
      # PATCH/PUT /elements/1
      def update
        @element.update(element_params)
      end
  
      # DELETE /elements/1
      def destroy
        @element.destroy
        redirect_to edit_post_path(@element.post)
      end
  
      private
      # Use callbacks to share common setup or constraints between actions.
  
      def set_post
        @post = current_author.posts.find(params[:post_id])
      end
  
      def set_element
        @element = @post.elements.find(params[:id])
      end
  
      # Only allow a trusted parameter &quot;white list&quot; through.
      def element_params
        params.require(:element).permit(:element_type, :content, :image)
      end
    end
  end
  </code></pre>
  <p>The link to the part of the tutorial I'm following in case you want to see it is:
  <a href="https://www.youtube.com/watch?v=OCJmF6ma-6w" rel="nofollow noreferrer">Rails Tutorial | Building a Blog with Ruby on Rails 6 - Part 3</a></p>