我試圖創建一個選擇,但是我得到這個錯誤:參數是丟失或爲空值:類
ActionController::ParameterMissing in ClassesController#create
param is missing or the value is empty: class # Never trust parameters from the scary internet, only allow the white list through.
def class_params
params.require(:class).permit(:classe, :segmento_id)
end
end
我試圖創建一個選擇,不過同樣是在退換錯誤...如果它是一個簡單的選擇。我正在使用simple_form。
有人幫助我嗎?
我的形式:
<%= simple_form_for(@class) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :classe %>
<%= f.collection_select :segmento_id, Segmento.all, :id, :categoria, prompt: 'Selecione uma Categoria', input_html: { class:'form-control' } %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
我的控制器:
class ClassesController < ApplicationController
before_action :set_class, only: [:show, :edit, :update, :destroy]
# GET /classes
# GET /classes.json
def index
@classes = Classe.all
end
# GET /classes/1
# GET /classes/1.json
def show
end
# GET /classes/new
def new
@class = Classe.new
end
# GET /classes/1/edit
def edit
end
# POST /classes
# POST /classes.json
def create
@class = Classe.new(class_params)
respond_to do |format|
if @class.save
format.html { redirect_to @class, notice: 'Classe was successfully created.' }
format.json { render :show, status: :created, location: @class }
else
format.html { render :new }
format.json { render json: @class.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /classes/1
# PATCH/PUT /classes/1.json
def update
respond_to do |format|
if @class.update(class_params)
format.html { redirect_to @class, notice: 'Classe was successfully updated.' }
format.json { render :show, status: :ok, location: @class }
else
format.html { render :edit }
format.json { render json: @class.errors, status: :unprocessable_entity }
end
end
end
# DELETE /classes/1
# DELETE /classes/1.json
def destroy
@class.destroy
respond_to do |format|
format.html { redirect_to classes_url, notice: 'Classe was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_class
@class = Classe.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def class_params
params.require(:class).permit(:classe, :segmento_id)
end
end
感謝您的幫助,真的,這就是問題所在。 –