lundi 10 juin 2019

How do I update controller param to accept nested attributes with rails?

I am working on a rails app, I was wondering how to update controller params to accept nested attributes with rails, this is the existing controller;

def create
    @product = Product.new(product_params)
    if @product.save
      redirect_to product_path(@product), notice: 'Product was successfully created.'
    else
      render :new
    end
  end

  def update
    if product.update(product_params)
      redirect_to product_path(product), notice: 'Product was successfully updated.'
    else
      render :edit
    end
  end

 def product_params
    params.require(:product).permit(
      :sku, :name, :shipping_option_id, :product_region_id
    )
  end

I was wondering if I need to add a different attribute, do I do it with create or update method in controller?

Aucun commentaire:

Enregistrer un commentaire