Search code examples
ruby-on-railsrubysubmitlink-to

Redirect to new view with submit_tag in Rails


I have the following submit_tag button

<%= submit_tag("Save Email".upcase, name:"email_change","data-target":"email_change.submit") %>

I am trying to have it redirect to a new view, similar to what is done with using link_to. Is there a way to do something similar using the submit button?


Solution

  • You can do:

    <% link_to some_path do %>
      <%= submit_tag("Save Email".upcase, name:"email_change","data-target":"email_change.submit") %>
    <% end %>
    

    The 'Rails' way to do this would probably be to wrap the redirect in some conditional logic in your controller action, especially if you're submitting data from a form