ruby-on-rails - Carrierwave通过url获取图片

标签 ruby-on-rails ruby carrierwave image-upload

我需要通过 url 获取一些图片。

网址类似于 http://img.wallsbay.com/large/2014/05/2665.jpg但 2014 和 2665 正在发生变化。

我的 Controller 有这个参数:

  def image_params
    params.require(:image).permit(:content, :remote_content_url, :id)
  end

我试着像这样从 url 中获取图像:

@image.remote_content_url = 'http://img.wallsbay.com/large/#{:content}/05/#{:id}jpg'

但是 remote_content_url 是未定义的方法。

最佳答案

remote_<attr_name>_url属性是通过给定的 URL 上传图片。

@model.remote_content_url = "http://img.wallsbay.com/large/2014/05/2665.jpg"
@model.save
@model.content_url // => "<upload-dir>/2665.jpg"

使用 @model.content_url检索上传图片的 url。

要应用转换,请使用 @model.content_url(:square) .

关于ruby-on-rails - Carrierwave通过url获取图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39074740/

相关文章:

ruby-on-rails - Action 电缆不工作我必须刷新两个选项卡才能看到消息

javascript - 开发模式下 Assets 编译缓慢

ruby-on-rails - Rails 4 - CarrierWave default_url 不适用于 Assets 图像

ruby-on-rails - stub 图像 url 并返回图像

ruby-on-rails - rails : Validates greater_than_or_equal_to 0 does not work

ruby-on-rails - 使用带有 remote: true 的 ajax 的 Ruby 表单会给出 ActionController::InvalidAuthenticityToken 错误。经典提交不

sql - 显示消息数组中的最后一条消息

ruby - 获取 Ruby 中的所有元组

ruby - 摘要的 Base-36 表示

ruby-on-rails - 错误在 rails 中显示两次