Robert Farese
Joined
Activity
Posted in Logic on nested forms/related tables
Hi Simon, I think this is more complicated than it seems on the surface. My initial thought was that you are missing a location
object. This Location
object would be associated with the Roast
class. So calling roast.locations
would return something like this:
{ "US" => ["Northeast", "Southwest"], "England" => ["London"] }
I'd have the country and regions classes outline just like you'd mentioned where country has many regions and a region belongs to a country and use those associations to build the locations. The benefit to this, from my perspective, is that you could have one location associated with more than one roast.
I'd look at a couple of ways to model this with [1] making sure the associations all made sense [2] making sure I'm minimizing any repetative data in the database [3] looking at using scopes and includes to get all the appropriate data out of the database and [4] looking at potentially using a multi-transitive association(s) here.
Here are a few links that might help in your process:
- https://www.sitepoint.com/master-many-to-many-associations-with-activerecord/
- http://guides.rubyonrails.org/association_basics.html
Hope that helps and doesn't confuse things...
Hi Jon, I'd try using an s3 bucket on AWS with either the carrierwave gem or paperclip gem and then secure the s3 bucket to only allow authenticated users to access it. Here are a couple of links that might help:
- https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Secure-uploaded-file-in-S3-and-make-it-only-accessible-by-supplying-secret-token%3F
- https://github.com/thoughtbot/paperclip/wiki/Restricting-Access-to-Objects-Stored-on-Amazon-S3
If the file download speed is going to hurt your app, perhaps moving it off into a background job with something like Sidekiq would be the answer. I've never used Sidkiq for this but I'd imagine its possible.
Lastly, why are the files so large to begin with? Do they have to be? If not, then perhaps upon ingestion of the files you resize them to something a little more "web friendly" to speed up download times in the future.
Hi Mark, I'm with Jacob. If you could show the code that would be great.
Also, what are you trying to do? Do you have a single page with multiple objects executing different types of CRUD functionality? If thats the case then perhaps you should use a view object that is a single model that represents all the models on that page. That way you can maintain RESTful routes and not have to try and share object id's accross controllers.
I'm sure Chris has some content around executing this kind of strategy. If not, I'm happy to share some additional context if need be.
I'm just getting started on a multitenant application for the lending / finance space. I've looked into Apartment, Milia, Act_as_tenant, etc. but none seemed to really fit what I'm trying to do.
I'll need different types of accounts. The interface / view templates will be different for a lender, for example, than for a borrower. I'm anticipating needed a lot of different classes, functionality, and different API's across the different types of accounts. This starts to sound like something that would be a good basis to start thinking about a services oriented architecture and a distributed system, however, for efficiency and time, I don't want to jump into that at the outset. I'd prefer to keep it as a monolith to start and break it out should the need arise in the future.
Here is what I was thinking as a general structure:
- The Account class would be the tenant
- Account has a subdomain and a category
- Account#category would be set as an enum with category: [:lender, :borrower, :insurer, :admin]
- The :admin under Account#category is a master level account for us internally to gain access to any account and to see our own dashboards for viewing customer analytics
- Account has_many companies
- Company belongs_to an account
- Comany has_many users
- User belongs_to a company
- Company has_many admins
- Admin belongs_to a company
- Account has_many users through company
- Account has_many admins through company
The issue I ran into with Apartment, for example, is the inability to add models that are unique to a specific type of tenant. For example, Lenders will have the ability to submit a Bid (loan offer with terms) to a borrower (so that the borrower can recieve multiple offerst from multiple lenders). I don't want to have a Bid added for a Borrower account in the DB as well, nor would I like the Bid excluded from the tenant and placed in a global space.
I was thinking that I could have Account type isolated into its own gem / engine so it would be similar to Dan Manges article about building a modular Rails monolity app with gems. The only difference is that in the /app folder I'd have the shared functionality between the tenants.
I have so many questions I'm not sure where to start! General feedback on this structure, how to go about accomplishing this, any potential resources you might know of, etc. is all welcome! So glad to be a part of GoRails! I hesitated too long to join!