Coming in to the thread a bit late here, but I think you should look into using PostgreSQL's schemas to separate the data for your tenants. The benefit of this is that in order to scope the data so that you're only showing one tenant's data, it's as easy as switching the schema lookup path to being just for that user's schema and the public schema.
You can do this very easily with the Apartment gem: https://github.com/influitive/apartment Apartment::Database.create(account.database_name) Where database_name is a unique attribute on your model. That command will create a new schema and run your migrations in that schema. In a before_filter in your controller you can look up the account object, and then switch to it using this method: Apartment::Database.switch(account.database_name) Subsequent calls to your models will look up data only from the named schema, which will have a completely unique set of IDs from the same table in different schemas. I know it sounds like you're pretty set on what you're doing now. This PostgreSQL schema usage is just something to consider. I'm using this in the multitenancy book I'm writing (http://leanpub.com/multi-tenancy-rails), and we've used this at Spree on some of our side projects to great success. Just thought you would like to know an alternative. On 4 April 2013 21:42, Rich Buggy <[email protected]> wrote: > Perfect!! That's solved the routing and now it works exactly the way I > wanted. Definitely something that needs a blog post this week. > > Rich > > > On Thu, Apr 4, 2013 at 5:03 PM, Paul Annesley <[email protected]> wrote: > >> Have you looked at #to_param on ActiveModel / ActiveRecord? >> Also I recommend an equivalent .from_param(param) class method on such >> models. >> >> class Something < AR::Base >> def to_param >> customer_number >> end >> def self.from_param(param) >> where(customer_number: param).first! >> end >> end >> >> — Paul >> >> >> On 04/04/2013, at 10:54 AM, Rich Buggy <[email protected]> wrote: >> >> > Thanks to everyone who replied. >> > >> > @Ben: your approach sounds like what I already have. There is an >> invoice_number that's manually calculated in addition to the id. What I was >> hoping to do is use the invoice_number in the route instead of id. For >> example: My existing route is /:tenant/invoices/:id but I would prefer >> /:tenant/invoices/:invoice_number. Doing this seems involve fighting the >> framework so I was hoping there may have been an easier way with AR >> involving changing how the id was calculated. I'll just live with this for >> now so I don't slow down development. I can revisit it when I'm further >> down the track. >> > >> > Rich >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby or Rails Oceania" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/rails-oceania?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > -- > Zoombug Pty Ltd > www.zoombugmedia.com > > -- > You received this message because you are subscribed to the Google Groups > "Ruby or Rails Oceania" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/rails-oceania?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rails-oceania?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
