![](/img/trans.png)
[英]Ruby on Rails: How to chain strong parameter if some of the parameters are nested attributes?
[英]How to get only nested params in strong parameter in ruby on rails
如何從中獲取唯一的need_attributes
?
def needy_params
params.require(:needy).permit(:user_name, :user_email, :needs_attributes: [:name, :description, :amount_required, :country_id, :city_id])
end
我是否可能needs_attributes
獲得needs_attributes
或編寫這樣的新方法?
def need_param
params.require(:needy.needs_attributes).permit(:name, :description, :amount_required, :country_id, :city_id)
end
這將為您工作:
def needs_attributes_param
params.require(:needy).require(:needs_attributes).permit(
:name, :description, :amount_required, :country_id, :city_id
)
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.