Brendan Feltrup-Exum

Joined

280 Experience
2 Lessons Completed
0 Questions Solved

Activity

I have tried doing something like this, but it kind messes things up. Between the shallow part and some of the controller/views parts I am lost.

resources :projects, shallow: true do
resources :script_locations do
resources :locations
end
end

Thanks in advance for any help.

So I am teaching myself rails through online tutorials and such. I have followed many on how to make a CRUD. I have learned about nested routes and how to accept attributes and dependents, etc. Now I want to work with a nested structure (multi tiered) keeping it shallow for the sake of best practices while connecting them all together. I have used this tutorial as how to do nested routes:
https://www.digitalocean.com/community/tutorials/how-to-create-nested-resources-for-a-ruby-on-rails-application

I have 3 Controllers: Project, Script Location and Location (I only edited the Script Location to do the nested routes)
4 Models: Project, Script Location, Location and Script Locations Location

class Project < ApplicationRecord
has_many :script_locations, dependent: :destroy
end

class ScriptLocation < ApplicationRecord
belongs_to :project
has_many :script_locations_locations
has_many :locations, through: :script_locations_locations
accepts_nested_attributes_for :locations
end

class Location < ApplicationRecord
has_many :script_locations_locations
has_many :script_locations, through: :script_locations_locations
accepts_nested_attributes_for :script_locations
end

class ScriptLocationsLocation < ApplicationRecord
belongs_to :location
belongs_to :script_location
end

I started by doing a traditional nested route for Project to Script Location since if I delete the Project I want the Script Location to be destroyed too. Now I know triple nesting is not advisable so I left Location on its own for now. I have my join table setup and its technically joining the models and connecting everything in the browser. I just would like to figure out how to from Script Locations add a new Location that is associated with that already. Can anyone suggest how to best do this?

In my current repo I have it where I can associate it after the fact from the Locations side. Key issue is that I want to keep the locations saved in the database even if I delete the project so I can associate them later to a Script Location.
https://github.com/senorlocksmith/nested_forms

Posted in Build Multitenancy App in a different way

Tabish, I had noticed this one. I am not a very seasoned developer and honestly trying to stay away from Postgres at the moment. I came from PHP and HTML so working with MySQL is easier at the moment. I cannot figure out how to get docker and postgres working properly and using WSL2 just gets very complicated. I am really hoping that Chris could help out by sharing some knowledge on how he got it working without domains.

What I have built thus far is a working app using devise and several crud models. I had hard coded a multitenant string based on another persons suggestions, but I am getting lots of leak through so I think it might be nicer if there was a gem that would separate the data for me vs me having to write each model and controller to filter based on the tenant. I have found some write ups but they are super generic and they only show you how to filter with a manual tenant listing. How on earth do you setup with Devise and an account. Can anyone provide a prebuilt repo that shows this? Even something simple where I sign up with my account and login and can switch accounts etc and it keeps the data seperate. I know postgres is good for this due to seperate schemas but I have also heard Apartment is EOL and no longer a good one to go with. Yes Activerecord multi tenant looks great but I cannot wrap my head around WSL and postgres properly and I have been banging my head for a week on it.

Posted in Build Multitenancy App in a different way

Chris Seelus,

I have tried over and over to get Acts_as_tenant to work with devise and opperate correctly but cannot get it to function together. Do you have any suggestions or places to look at a functioning codebase? I have managed to work with Devise quite well and be fine with that, but adding AAT starts causing problems looking for the tenant or account.

Brendan