Home>

I'm new to programming.
I get the following error:

When I checked the params, it seems that the data was sent, but after pressing the registration button, the above error occurs.
I would like you to teach me the solution.

protein controller.rb
 def index
    @proteins = Protein.all
  end
  def new
    @protein = Protein.new
  end
  def create
    @protein = Protein.new (proteins_params)
    if @ protein.save
      redirect_to root_path
    else else
      render: new
    end
  end
  def show
    @protein_image = @ protein.image
  end
  def edit
  end
  def update
    if @ protein.update (proteins_params)
      redirect_to protein_path
    else else
      render: edit
    end
  end
  def destroy
    if @ protein.destroy
      redirect_to proteins_path
    else else
      render: show
    end
  end

  private

  def move_to_new
    unless current_user == @user || current_user.admin?
      redirect_to root_path
    end
  end

  def item_set
    @protein = Protein.find (params [: id])
  end
end
  • Answer # 1

    def proteins_params
    params.require (: protein) .permit (: image,: name,: price,: energy,: prote,: salt,: Lipid,: carbo,: first,: second,: third,: fourth,: fifth). merge (user_id: current_user.id)
    end
    I was able to solve it safely by putting in!