我将数据从电子表格导入到应用程序数据库.
数据按行解析.每个解析的行看起来像:
{: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}
}
Run Code Online (Sandbox Code Playgroud)
要创建一个部门:
# 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
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误:
no implicit conversion of Symbol into String
Run Code Online (Sandbox Code Playgroud)
哪个指向
params.require(:department).permit(:name,:url,:institute_id)
Run Code Online (Sandbox Code Playgroud)
我该怎么办呢?谢谢!
我的模型中有一个before_validation回调。我无法找到如何在minitest rails中编写回调的测试用例。
test 'callback set_slug before_validation' do
company = Company.new(name: 'test')
mock_method = MiniTest::Mock.new
mock_method.expect :set_slug, 'clickapps1'
company.stub :set_slug, 'clickapps1' do
company.valid?
end
mock_method.verify
end
Run Code Online (Sandbox Code Playgroud)