我的代码存在问题。
这是控制器:
def create
@mean = TrasmissionMean.new(trasmission_mean_params)
if @mean.save
flash[:success] = "Mezzo di Trasmissione #{@mean.description}"
else
flash[:error] = "Error #{@mean.errors.full_messages}"
render :action => 'new'
end
end
def trasmission_mean_params
params.require(:mean).permit(:description)
end
我的代码存在问题。
这是视图,渲染形式为:
<div class="row">
<div class="col-md-10 col-md-offset-1">
<%= form_for @mean, :html => {:class => "form-horizontal" },:url => url_for(:controller => "trasmission_means", :action => "create" ) do |f| %>
<hr>
<%= render partial: "form", :locals => { :@mean => @mean, :f => f } %>
<hr>
<%= f.submit "Aggiungi", class: 'btn btn-success btn-lg pull-right' %>
<% end %>
</div>
</div>
渲染形式:
<div class="form-group">
<div class="col-lg-12">
<%= f.text_area :description, :rows => 4, class: 'form-control ', placeholder: 'Descrizione' %>
</div>
</div>
这是错误。我不明白问题出在哪里
ActionController::ParameterMissing in Protocol::TrasmissionMeansController#create
param缺失或值为空:mean
答案 0 :(得分:2)
参数基于类
def trasmission_mean_params
params.require(:mean).permit(:description)
end
在params散列中寻找均值但是你的类被称为TransmissionMean
,这意味着它应该是
def trasmission_mean_params
params.require(:transmission_mean).permit(:description)
end