Comments on: Rails Tip: Use Polymorphism to Extend your Controllers at Runtime https://blog.mattwynne.net/2009/07/11/rails-tip-use-polymorphism-to-extend-your-controllers-at-runtime/ Matt Wynne taking it one tea at a time Wed, 21 Aug 2019 12:59:53 +0000 hourly 1 https://wordpress.org/?v=6.2 By: Richie Vos https://blog.mattwynne.net/2009/07/11/rails-tip-use-polymorphism-to-extend-your-controllers-at-runtime/comment-page-1/#comment-762 Mon, 31 Aug 2009 21:01:33 +0000 http://blog.mattwynne.net/2009/07/11/rails-tip-use-polymorphism-to-extend-your-controllers-at-runtime/#comment-762 Very interesting approach to this problem. I’m dealing with a similar situation where I want to send different forms of xml to different clients and I was thinking about:

@things.to_xml(:api => '123')

OR

@things = blah
if x
  render 'api1'
elsif y
  render 'api2'
else
  render 'api3'
end

but your approach feels cleaner, though for simplicity I might just do something like

before_filter :determine_api

def determine_api
  @template = 'xyz'
end
]]>