简体   繁体   English

强参数Rails 4.1

[英]Strong Parameters Rails 4.1

Any idea why this isn't working? 知道为什么这行不通吗?

def user_params
  params.require(:user).permit({:book_ids => []}, :first_name, :last_name, :email, :password, :password_confirmation, :title, :company, :phone, :business_email, :business_phone)
end

Unpermitted parameters: book_ids 不允许的参数: book_ids

Use this: 用这个:

def user_params
  params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :title, :company, :phone, :business_email, :business_phone, :book_ids => [])
end

You must be passing book_ids as an array in your params, in that case you should permit them as :book_ids => [] and also at the end. 您必须在参数book_ids作为array传递,在这种情况下,应允许它们以:book_ids => [] 以及最后。

As per the chat session, OP had an issue with the drop down as it was set as multiple: false instead of multiple: true . 在聊天会话中,OP的下拉菜单存在问题,因为它设置为multiple: false而不是multiple: true Also, in order to facilitate the update action, a selected option needs to be specified. 另外,为了促进update动作,需要指定selected选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM