简体   繁体   中英

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.

html哈希中取出method

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

尝试这个:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM