loading...

re: How to best organize a Rails app folder? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: This is our current app folder... ▾ app/ ▸ adapters/ (** created by us, for dependencies in our "services" **) ▸ assets/ ▸ controllers/ ...
 

re folders:
i used to use app/services - eg ProductHunt is still structured that way

at some point the separation between a few classes in app/models and app/services just became weird - especially if they work super close together - eg a concern calling a service object

so in newer projects i just use app/models - keep in mind that models stands for classes that model your domain logic - not just persisted state

re namespaces:
i do the same setup as benito w/ the namespaces

usually the logic starts in the method - and when it becomes more than a 3 liner i extract it to some class so it easier to extend

eg

module Campaigns
  extend self
  class ParticipationRequired < StandardError; end
  class InviteRequired < StandardError; end

  # ....

  # simple method
  def allowed_to_join_late?(invite:)
    invite.present? && invite.allowed_to_join_late?
  end

  # more complex stuff
  def flag!(**args)
    Campaigns::Participation::Flag.flag!(**args)
  end```



re api/separation:
like benito i try to keep separation - as in: namespaces dont touch into the deeper parts of other namespaces. controllers neither

the exception are usually rake tasks and sometimes admin backend/stuff
Code of Conduct Report abuse