2016-06-09 103 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以外的東西。

事實上,儘量避免使用關鍵字作爲字段,屬性,方法,類名等。它混淆了語言運行時,框架和其他開發人員。

相關問題