0 votes
in Ruby by
Given this controller code, which choice describes the expected behavior if parameters are submitted to the update action that includes values for the product's name, style, color, and price?

class ProductController < ActionController::Base

  def update

    @product = Product.find(params[:id])

    if @product.update_attributes(product_params)

      redirect_to(product_path(@product))

    else

      render('edit')

    end

  end

  private

  def product_params

    params.require(:product).permit(:name, :style, :color)

  end

end

 a. The product will not be updated and the edit template will be rendered.

 b. The product will not be updated and the controller will raise an ActiveModel::ForbiddenAttributes exception.

 c. The product will be updated with the values for name, style, and color, but the value for price will be ignored.

 d. The product will be updated with the values for name, style, color, and price.

1 Answer

0 votes
by

Given this controller code, which choice describes the expected behavior if parameters are submitted to the update action that includes values for the product's name, style, color, and price?

class ProductController < ActionController::Base

  def update

    @product = Product.find(params[:id])

    if @product.update_attributes(product_params)

      redirect_to(product_path(@product))

    else

      render('edit')

    end

  end

  private

  def product_params

    params.require(:product).permit(:name, :style, :color)

  end

end

 

 Correct answer is :-  The product will not be updated and the controller will raise an ActiveModel::ForbiddenAttributes exception.

Related questions

0 votes
asked Sep 2, 2022 in Ruby by DavidAnderson
0 votes
asked Aug 26, 2022 in Ruby by Robin
...