lundi 3 août 2020

How to call Select_tag in Create action in a model

Actually im getting my category model values from category to take input..... category_id act as a foreign key in Product Model I am taking input like this

<%= select_tag 'category', options_for_select(Category.pluck(:name, :id)), class: 'form-control', id: 'sel1' %>

And Pass Category Id in Product_controller Create action like this

def create
@product = Product.new(product_params)
@product.user = current_user

  private

def product_params
  params.require(:product).permit(:productname, :productprice, :productstatus,:image ,:category )
end

But when I create My product An error occurs that category Should be Present. I think that params[:category] not pass the category_id

Aucun commentaire:

Enregistrer un commentaire