ruby on rails - PORO presenter breaks url helpers -



ruby on rails - PORO presenter breaks url helpers -

i have started creating rails presenters using poro approach. illustration presenter resides in app/presenters/band_presenter.rb , here it's code:

class bandpresenter def method_missing(m, *args, &block) @band.send(m) end def initialize(band) @band = band end def thumb_url(size = :large_s) @band.images[size.to_s] if @band.images end end

and works good. however, if i'll utilize instance of presenter in rails url helper methods, breaks them. example:

@band = band.find(1) = link_to @band.name, band # => /bands/1 @band = @band.find(1) @band = bandpresenter.new(@band) = link_to @band.name, band # => /%23%3cbandpresenter:0x007f9139c50db0%3e/1

which seems legit. question - can somehow create presenter back upwards such way of using url helpers?

try defining to_param method

class bandpresenter def to_param @band.id end def model_name @band.model_name end end

another alternative might help defining respond_to_missing?, see here: http://robots.thoughtbot.com/always-define-respond-to-missing-when-overriding

class bandpresenter def respond_to_missing?(method_name, include_private = false) @band.respond_to?(method_name, include_private) || super end end

ruby-on-rails ruby mvp

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -