如何发送两个链接的方法作为符号?
How do I send a two chained methods as a symbol?
为了使用 friendly_id 正确搜索我的帖子,我使用此查询:
Post.friendly.find(params[:id])
但我需要将此方法打包并发送给我的演示者 class gem, decent_exposure
。这给了我一个很好的地方来包含一个 method
来获取我的对象。
默认情况下,此方法为 :find
。正如他们的代码中所写:
def finder
options[:finder] || :find
end
scope.send(finder, id) # scope here would mean Post
如何通过选项发送,这两种方法查询作为符号?
类似于
scope.send(:finder).try(:id) ??
如果您在 Post 上定义了 class 方法,请快速查看他们的文档,然后您应该能够使用它。
class Post
def self.find_with_friendly(id)
friendly.find(id)
end
end
那你可以做
expose(:post, finder: :find_with_friendly)
很确定这应该有效。
为了使用 friendly_id 正确搜索我的帖子,我使用此查询:
Post.friendly.find(params[:id])
但我需要将此方法打包并发送给我的演示者 class gem, decent_exposure
。这给了我一个很好的地方来包含一个 method
来获取我的对象。
默认情况下,此方法为 :find
。正如他们的代码中所写:
def finder
options[:finder] || :find
end
scope.send(finder, id) # scope here would mean Post
如何通过选项发送,这两种方法查询作为符号?
类似于
scope.send(:finder).try(:id) ??
如果您在 Post 上定义了 class 方法,请快速查看他们的文档,然后您应该能够使用它。
class Post
def self.find_with_friendly(id)
friendly.find(id)
end
end
那你可以做
expose(:post, finder: :find_with_friendly)
很确定这应该有效。