vendredi 17 avril 2015

Rails call same action code from two controllers (with a small difference)

I have two different routes that need to output the same page with only minor differences (title, open graph tags, etc.)


routes.rb



match 'referral/:ref' => 'referral#home'
root :to => "home#index"


I'm not willing to copy the exact same code from the HomeController to the ReferralController and I don't want a redirect, because the title and OG tags must be different (in order to have a special referral title when the page is shared)


With an express.js app (which I'm more familiar with), I would add a middleware in the referral route and then call the HomeController#index action. So everything would be done at the routing level.


What's the idiomatic approach in Rails?


Thanks, Laurent


Aucun commentaire:

Enregistrer un commentaire