【问题标题】:How to get Paperclip image URL through GraphQL Ruby如何通过 GraphQL Ruby 获取回形针图像 URL
【发布时间】:2019-07-09 14:02:02
【问题描述】:

我正在尝试通过GraphQL Ruby gem 提供该项目的回形针缩略图变体:

app/graphql/types/item_type.rb:

class Types::ItemType < Types::BaseObject
  description 'An item'
  field :title, String, null: false
  field :thumbnail_image, String, null: true

  def thumbnail_image
    item.image.url(:thumb_2x)
  end
end

这只会导致以下错误:

"message": "undefined local variable or method `item' for #<Types::ItemType:0x00007ff3f1dbc4e0>"

什么是让它工作的正确方法?我需要解析器吗?

【问题讨论】:

    标签: ruby-on-rails graphql paperclip graphql-ruby


    【解决方案1】:

    想通了,我需要这样做:

    def thumbnail_image
      object.image.url(:thumb_2x)
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 2016-05-30
      • 2013-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多