2016-06-09 80 views
0

我试图创建一个选择,但是我得到这个错误:参数是丢失或为空值:类

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 

回答

1

有错字在params.require(:CLASSE)

def class_params 
    params.require(:classe).permit(:classe, :segmento_id) 
end 
+0

感谢您的帮助,真的,这就是问题所在。 –

0

尝试重命名classclass以外的东西。

事实上,尽量避免使用关键字作为字段,属性,方法,类名等。它混淆了语言运行时,框架和其他开发人员。

相关问题