Search code examples
ruby-on-railsrubyruby-on-rails-4twitter-bootstrap-3bootstrap-form-helper

How would the following change using the bootstrap_form_for gem?


## I'm not sure how to re-write the :action=> tag in my old code snippet below to use the boostrap_form_for context. Can someone help?

        <%= form_tag(:action => 'attempt_login') do %>
         <%= error_messages_for(@user) %>
          <table>
            <tr>
              <th>email</th>
              <td><%= email_field_tag(:email) %></td>
            </tr>
            <tr>
              <th>password</th>
              <td><%= password_field_tag(:password) %></td>
            </tr>

            </table>
            <div class="frm-button">
                <td><%= submit_tag("login") %></td>
            </div>  
           <% end %>  

Solution

  • Use the url: '' instead. If you have problem finding the right url, run rake routes and search for your action in there.

    You should have in your routes.rb something like:

    match '/attempt_login', to: 'login_controller#attempt_login', via: :post
    

    then edit your form:

    <%= bootstrap_form_for(url: '/attempt_login', method: :post) do |f| %>
    ...
    <% end %>
    

    Hope that helps.