0

In order to properly search my Posts using friendly_id, I use this query :

Post.friendly.find(params[:id])

But I need to wrap this method up and send it to my presenter class gem, decent_exposure. Which gives me a fancy place to include a method that would fetch my object.

By default, this method is :find . As written in their code :

def finder
  options[:finder] || :find
end

scope.send(finder, id) # scope here would mean Post

How can I send via options, this two method query as a symbol?

Trip
  • 26,756
  • 46
  • 158
  • 277

2 Answers2

3

Looking at their documentation quickly if you define a class method on Post you should then be able to use that.

class Post
  def self.find_with_friendly(id)
    friendly.find(id)
  end
end

Then you can do

expose(:post, finder: :find_with_friendly)

Pretty sure this should work.

j-dexx
  • 10,286
  • 3
  • 23
  • 36
0

Something like

scope.send(:finder).try(:id) ??

Rajeev Sharma
  • 1,527
  • 2
  • 13
  • 16