【问题标题】:Rails 4 strong params error: no implicit conversion of Symbol into StringRails 4强参数错误:没有将符号隐式转换为字符串
【发布时间】:2013-05-09 18:22:10
【问题描述】:

我正在将数据从电子表格导入应用数据库。

数据按行解析。每个解析的行看起来像:

{:department=>{
  :school=>"Graduate School of Business",
  :name=>"Graduate School of Business",
  :program=>"MBA Program",
  :url=>"http://www.gsb.stanford.edu/mba",
  :intro=>"The Stanford MBA Program is a two-year, full-time, residential program.",
  :students_number=>"Approximately 80 annually",
  :students_with_aids_number=>nil,
  :gre_scroe=>nil,
  :toefl_score=>nil,
  :world_rank=>nil,
  :us_rank=>nil,
  :without_aid_deadline=>nil,
  :with_aid_deadline=>nil,
  :salary=>nil,
  :institute_id=>1}
}

创建部门:

 # att is the hash shown above
    department = Department.new(department_params(att))
    if !department.save
        puts "Error: \n department can't be save: #{department.errors.full_messages}"
    end

 def department_params params
   params.require(:department).permit(:name,:url,:institute_id)
 end

但我得到了错误:

no implicit conversion of Symbol into String

指向

params.require(:department).permit(:name,:url,:institute_id)

我该如何解决?谢谢!

【问题讨论】:

  • 于君:你还在吗? ;)

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


【解决方案1】:

Getting rails-api and strong_parameters to work together

我认为它会非常相似。您只需要包含ActionController::StrongParameters 不需要,如链接问题中所述。

在我的例子中,它添加了新的初始化器

ActionController::API.send :include, ActionController::StrongParameters

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2017-01-19
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    • 1970-01-01
    相关资源
    最近更新 更多