Keon Cummings
Keon Cummings

Reputation: 1811

My submit button won't work in rails and I'm not sure why

I'm creating a simple form in rails and the submit button doesn't work. I think I'm missing something obvious here but the html seems to be fine (I'm far froma front end expert). Any advice or pointers?

 <div class="container">
            <div class="row">
                <div class="col-lg-12 text-center">
                    <h2>Apply</h2>
                    <hr class="star-primary">
                </div>
            </div>
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2">
                        <div class="row control-group">
                            <% if @user.errors.any? %>
                              <div id="error_explanation">
                                <div class="alert alert-error">
                                  The form contains <%= pluralize(@user.errors.count, "error") %>.
                                </div>
                                <ul>
                                <% @user.errors.full_messages.each do |msg| %>
                                  <li>* <%= msg %></li>
                                <% end %>
                                </ul>
                              </div>
                            <% end %>
                            <div class="col-xs-12 floating-label-form-group controls">
                                <%= form_for @user, url: users_path(@user), :html => {:method => :post} do |f| %>
                                    <%= f.label :name %>
                                    <%= f.text_field :name, class: "form-control", placeholder: 'Name' %>
                                    <%= f.label :email%>
                                    <%= f.text_field :email, class: "form-control", placeholder: "Email" %>
                                    <%= f.label :address%>
                                    <%= f.text_field :address, class: "form-control", placeholder: "Address" %>
                                    <%= f.label :phone %>
                                    <%= f.text_field :phone, class: "form-control", placeholder: "Phone Number" %>
                                    <%= f.submit "Apply"%>

                                <%end%>

                            </div>
                        </div>
                </div>
            </div>
        </div>

Also, when the submit button fails, nothing happens. No error messages, no console errors. Nothing.

Upvotes: 0

Views: 167

Answers (3)

Nikola Todorovic
Nikola Todorovic

Reputation: 310

Can you try this one:

<%= form_for @user, url: {action: "create"} do |f| %>
    ...
    ...
    <%= f.submit "Apply" %>
<% end %>

But I strongly suggest you to use simple_form gem.

Upvotes: 0

Emu
Emu

Reputation: 5895

Try this:

<%= form_for @user, :url => {:controller => "your-controller-name", :action => "your-action-name"} do |f| %>

Upvotes: 0

kjmagic13
kjmagic13

Reputation: 1318

Take method out from the html hash?

form_for @user, url: users_path(@user), :method => :post do |f|

Upvotes: 1

Related Questions