We're developing a conference management app and most of the resources is nested resource of conference. Now, we decided to use subdomains for conference homepages and got trouble on refactoring resources.
Current url scheme is like:
/conferences/:id/speeches
/conferences/:id/manage
We want to move /conferences/:id part to subdomain and use resources like:
conferenceid.sitename.com/speeches
conferenceid.sitename.com/manage
Here are the current routes file: https://github.com/kodgemisi/confdeck/blob/development/config/routes.rb#L17
What's the best way to make this transition? How can we prevent current url helpers?
first lets tweak your subdomain class. the following code should be enough
class Subdomain
def self.matches?(request)
request.subdomain.present? && request.subdomain != 'www'
end
end
then you should be able to call it in the routes with the following
constraints(Subdomain) do
resource :conference, path: "/" do
member do
get 'apply'
post 'apply' => "conferences#save_apply"
end
end
Then in your Controller you go like this:
Conference.find_by_slugged!(request.subdomain)
(i saw you use friendly id, so i think your subdomain is sluggged
of the Conference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With