hashrocket / decent_exposure

A helper for creating declarative interfaces in controllers
MIT License
1.81k stars 107 forks source link

Allow multiple exposing #204

Closed sumskyi closed 3 months ago

sumskyi commented 3 months ago

I'd like to have the possibility to expose multiple things once, like:

expose(:pagination, :users) { pagy(User.all) }

https://github.com/ddnexus/pagy, i.e. @pagy, @records = pagy(Product.all) returns an array :)

dillonhafer commented 3 months ago

I ended up with this:

class Controller
  expose(:pagination) { find_users.first }
  expose(:users) { find_users.last }

  private def find_users
    @find_users ||= pagy(User.all)
  end
end
sumskyi commented 3 months ago

Workaround from @dillonhafer is fine.

mattpolito commented 3 months ago

@sumskyi I would've suggested something similar as well... glad that worked out. I don't think it's be a good idea to change expose's signature to accommodate the rare case that it'd be used in this way.