Redirect Using Select (Dropdown) in Rails

I wanted to create a select menu that would route the user after an option was selected. I added a select like this (in this case, the options were read in from a list of constants:

<%= form_with do |f| %> 
  <%= f.select :example, (options_for_select(STATES)), {include_blank: true} %> 
<% end %>

Some Javascript was added. On change of the select, the user was redirected. In my case, the value from the select was part of the URL, so I took the value from the select (‘url’) and then added that to the url specified for window.location.

<script type="text/javascript">
 $('#example').change(function() {      
   var url = $(this).val();       
   window.location = 'put your URL here'
 });
</script>

Sign Out Wasn’t Working with Devise for Me

Devise’s Sign Out wasn’t working for me. I’ve seen other solutions, but they didn’t worked for me. However, I found an answer that worked for me on Devise’s wiki.

Previously, I used this link:

<%= link_to "Logout", destroy_user_session_path, method: :delete %>

However, that wasn’t working, so I changed (in config/initializers/devise.rb in ):

config.sign_out_via = :delete

to:

config.sign_out_via = :get

and revised the link to (removed “method: :delete”):

<%= link_to "Logout", destroy_user_session_path %>