繁体   English   中英

ActionController :: ParameterMissing不知道怎么了

[英]ActionController::ParameterMissing Don't know whats wrong

我一直收到此错误,我已经有一段时间没有使用ruby了,所以我真的不知道如何解决它。

param is missing or the value is empty: sch

Extracted source (around line #72):
70
71
72
73
74

    # Never trust parameters from the scary internet, only allow the white list through.
    def sch_params
      params.require(:sch).permit(:date, :time, :user_id)
    end
end

Rails.root: C:/Sites/web

Application Trace | Framework Trace | Full Trace
app/controllers/sches_controller.rb:72:in `sch_params'
app/controllers/sches_controller.rb:27:in `create'
Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"cHq54V7aVCjeBz0udZAYjGiojgrqDANx/BS+oMQ+N+0=",
 "sche"=>{"date(1i)"=>"2014",
 "date(2i)"=>"4",
 "date(3i)"=>"21",
 "time(1i)"=>"2014",
 "time(2i)"=>"4",
 "time(3i)"=>"21",
 "time(4i)"=>"17",
 "time(5i)"=>"37",
 "user"=>"steve"},
 "commit"=>"Create Sche"}

这是我的控制器

class SchesController < ApplicationController
  before_action :set_sch, only: [:show, :edit, :update, :destroy]

  # GET /sches
  # GET /sches.json
  def index
    @sches = Sche.all
  end

  # GET /sches/1
  # GET /sches/1.json
  def show
  end

  # GET /sches/new
  def new
    @sch = Sche.new
  end

  # GET /sches/1/edit
  def edit
  end

  # POST /sches
  # POST /sches.json
  def create
    @sch = Sche.new(sch_params)

    respond_to do |format|
      if @sch.save
        format.html { redirect_to @sch, notice: 'Sche was successfully created.' }
        format.json { render :show, status: :created, location: @sch }
      else
        format.html { render :new }
        format.json { render json: @sch.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /sches/1
  # PATCH/PUT /sches/1.json
  def update
    respond_to do |format|
      if @sch.update(sch_params)
        format.html { redirect_to @sch, notice: 'Sche was successfully updated.' }
        format.json { render :show, status: :ok, location: @sch }
      else
        format.html { render :edit }
        format.json { render json: @sch.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /sches/1
  # DELETE /sches/1.json
  def destroy
    @sch.destroy
    respond_to do |format|
      format.html { redirect_to sches_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_sch
      @sch = Sche.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def sch_params
      params.require(:sch).permit(:date, :time, :user)
    end
end

我真的不知道发生了什么,我已经尝试过搜索该问题,但是我仍然没有找到答案。非常感谢您的帮助。

用这个:

   def sch_params
      params.require(:sche).permit(:date, :time, :user)
    end

你的控制器名称为SchesController所以在PARAMS哈希你得到钥匙sche ,而不是sch

如果你看一下PARAMS产生,通知sche

“ sche” => {“ date(1i)” =>“ 2014”,“ date(2i)” =>“ 4”,“ date(3i)” =>“ 21”,“ time(1i)” => “ 2014”,“ time(2i)” =>“ 4”,“ time(3i)” =>“ 21”,“ time(4i)” =>“ 17”,“ time(5i)” =>“ 37 “,”用户“ =>”史蒂夫“}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM