如何在rails上的ruby中仅获取强参数中的嵌套参数

时间:2015-08-04 07:48:17

标签: ruby-on-rails ruby ruby-on-rails-4

如何从此获得唯一的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或者像这样编写新方法?

def need_param
  params.require(:needy.needs_attributes).permit(:name, :description, :amount_required, :country_id, :city_id)
end 

1 个答案:

答案 0 :(得分:1)

这对你有用:

def needs_attributes_param
  params.require(:needy).require(:needs_attributes).permit(
    :name, :description, :amount_required, :country_id, :city_id
  )
end