NoMethodError in Controller#create - undefined method `level' for... impossible to save

369 Views Asked by At

I am building a ruby on rails app. I have problems to create an Outfit. It throws an error I don't understand

NoMethodError in OutfitsController#create undefined method `level' for

But I have nothing named level in any of my code .. I don t get it ! here is the screenshot screenshot of the error, and my code.

 def create
    @user = current_user
    @outfit = Outfit.new(outfit_params)
    @outfit.user = current_user
    if @outfit.save
      redirect_to outfits_path
      flash[:notice] = "Outfit created"
    else
      flash[:notice] = "Something went wrong, please check the form again"
    end
  end

 private

  def outfit_params
    params.require(:outfit).permit(:name, :pet, :price, :color, :style, :size, :description, photos:[])
  end

  def update_outfit_params
    params.require(:outfit).permit(:name, :pet, :price, :color, :style, :size,:description,  photos:[])
  end

I tried to use @outfit.save! no succes, it always tells me " NoMmethod 'level' ..."! That's what I don't get, never happened before.. where does that 'level' come from ?

Here is my model

class Outfit < ApplicationRecord
  belongs_to :user
  has_many_attached :photos

  SIZE = ['S', 'M', 'L']
  validates_inclusion_of :level, :in => SIZE

end

0

There are 0 best solutions below