简体   繁体   English

我的“提交”按钮无法正常使用,我不确定为什么

[英]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. 我正在用rails创建一个简单的表单,并且提交按钮不起作用。 I think I'm missing something obvious here but the html seems to be fine (I'm far froma front end expert). 我想我在这里遗漏了一些明显的东西,但是html似乎还不错(我离前端专家很远)。 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. 但我强烈建议您使用simple_form gem。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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