我目前正在使用Ruby on Rails开发一个应用程序,我使用的是carrierwave-Gem。如果我从计算机中选择一个图像并保存模型,一切都按预期工作。
但是现在,我想将图像-Url直接存储在数据库中,而根本不使用carrierwave(也没有远程上传)。我只想存储我通常存储Image的字段中的外部API获取的图像-Url(在Carrierwave的帮助下)。
这是我当前的方法,无法存储图片-Ull:
def create_with_api
@job = Job.friendly.find(request.env['omniauth.params']['job_id'])
auth = request.env['omniauth.auth']
@applicant = @job.applicants.new(
is_male: auth.extra.raw_info.gender == 'm' ? true : false,
first_name: auth.extra.raw_info.first_name,
last_name: auth.extra.raw_info.last_name,
street: auth.extra.raw_info.business_address.street,
zip_code: auth.extra.raw_info.business_address.zip_code,
city: auth.extra.raw_info.business_address.city,
education: 'other',
telephone: auth.extra.raw_info.business_address.phone,
email: auth.extra.raw_info.active_email,
birthday: Date.new(auth.extra.raw_info.birth_date.year, auth.extra.raw_info.birth_date.month, auth.extra.raw_info.birth_date.day),
passport_photo_url: auth.extra.raw_info.photo_urls.large
)
raise @applicant.to_json
end
这是引发异常时显示的内容:
{"id":null,"is_male":true,"first_name":"John","last_name":"Doe","street":"Foo bar street 123","zip_code":"12345","city":"Johnscity","telephone":"12345678","email":"foo@bar.de","birthday":"2012-12-13","job_id":9,"created_at":null,"updated_at":null,"education":"other", "passport_photo_url":{"url":null}}
似乎我需要做一些像
这样的事情passport_photo_url: { url: 'http://www.example.com/image.png' }
但这也无声地失败了。
任何建议
提前致谢!