Skip to content

Instantly share code, notes, and snippets.

@andrewhao
Last active January 25, 2023 18:31
Show Gist options
  • Save andrewhao/d9bf84a77774d8eba639f12fbaad5c29 to your computer and use it in GitHub Desktop.
Save andrewhao/d9bf84a77774d8eba639f12fbaad5c29 to your computer and use it in GitHub Desktop.
Domain-oriented Rails file structures
module Ridesharing
class DriverController
append_view_path(‘app/domains’)
end
end
# Before
module Ridesharing
class Vehicle
belongs_to :driver
end
end
# After:
module Ridesharing
class Vehicle
belongs_to :driver, class_name: "Ridesharing::Driver"
end
end
app/
domains/
ridesharing/
driver.rb
driver_controller.rb
drivers/
show.html.haml
app/
domains/
ridesharing/
vehicle.rb
vehicles_controller.rb
trip.rb
service_tier.rb
trip_price.rb
...
marketing/
campaign.rb
campaigns_controller.rb
contact.rb
...
customer_support/
issue.rb
issues_controller.rb
...
identity/
user.rb
users_controller.rb
role.rb
session.rb
...
ecommerce/
payment.rb
payments_controller.rb
charge.rb
invoice.rb
pricing_tier.rb
...
# Before:
class Driver < ActiveRecord::Base
end
# After:
module Ridesharing
class Driver < ActiveRecord::Base
end
end
app/
models/
driver.rb
controllers/
driver_controller.rb
views/
drivers/
show.html.haml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment