我在传输器控制器中有一个创建操作
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 %>
什么都没发生。表单不会重新加载,数据不会保存到数据库中。为什么我的表单没有提交?