单击提交rails时没有任何反应

时间:2013-09-15 11:04:33

标签: ruby-on-rails ruby forms ruby-on-rails-4 rails-postgresql

我在传输器控制器中有一个创建操作

 def create
    @transporter = Transporter.new(transporter_params)

    respond_to do |format|
      if @transporter.save
        format.html { redirect_to @transporter, notice: 'Transporter was successfully created.' }
        format.json { render action: 'show', status: :created, location: @transporter }
      else
        format.html { render action: 'new' }
        format.json { render json: @transporter.errors, status: :unprocessable_entity }
      end
    end
    @transporter.save
    end
private
def transporter_params
      params.require(:transporter).permit(:name, :phone, :id_number)
    end

但是当我尝试使用此表单提交表单时:

<%= form_for(@transporter) do |f| %>
  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :phone %><br>
    <%= f.text_field :phone %>
  </div>
  <div class="field">
    <%= f.label :id_number %><br>
    <%= f.text_field :id_number %>
  </div>
  <div class="actions">
    <%= f.submit 'Add transporter', class: 'btn btn-success' %>
  </div>
<% end %>

什么都没发生。表单不会重新加载,数据不会保存到数据库中。为什么我的表单没有提交?

0 个答案:

没有答案