Agile Web Development with Rails 6 - Iteration K4 Missing method: :get attribute for locale switcher form (PDF p 280)

If you use the code snippet in the book for the form_tag, you will get a routing error because it will navigate to the

Book version: Form tag will use POST and create routing error

      <aside>
        <%= form_tag store_index_path, class: 'locale' do %>
          <%= select_tag 'set_locale',
            options_for_select(LANGUAGES, I18n.locale.to_s),
            onchange: 'this.form.submit()' %>
          <%= submit_tag t('.locale_submit'), id: 'submit_locale_change' %>
        <% end %>
      </aside>

Fixed (using method: :get to specify the GET verb for the form)

      <aside>
        <%= form_tag store_index_path, method: :get, class: 'locale' do %>
          <%= select_tag 'set_locale',
            options_for_select(LANGUAGES, I18n.locale.to_s),
            onchange: 'this.form.submit()' %>
          <%= submit_tag t('.locale_submit'), id: 'submit_locale_change' %>
        <% end %>
      </aside>
1 Like