0

I have traditionally used subdomains to scope apps between tenants in multi-tenant rails apps. For my current project, I think hanging a customer identifier as the first part of the url is a better approach.

I have figured out that I can scope to a parameter, so that (I think) solves the actual routing. Now, is there a clean way for me to generate these paths in my views and controllers?

For instance, if I have a "posts" resource, I want its URL to be

GET /:customer_id/posts/:post_id

Which seems to be working well, but is there an easier way to generate these url with helpers without manually passing in the :customer_id as a route parameter every time? I want to just be able to use

<%= post_path(@post) %>

Without having to hand it the customer ID (which seems brittle and repetitive)

I guess maybe a simpler way to ask, is it possible to append a default parameter to every generated url?

menacingly
  • 728
  • 4
  • 11

1 Answers1

1

You need to override url_options

class ApplicationController < ActionController::Base

  def url_options
    { :customer => @customer }.merge(super)
  end

end

More info in this answer

Community
  • 1
  • 1
Doug
  • 14,387
  • 17
  • 74
  • 104