Best practice for structuring a 'large' Rails app

后端 未结 6 423
情深已故
情深已故 2021-01-30 18:27

My question here is seeking best practice, general advice and insight, rather than a solution to a specific problem.

I am in the early stages of planning out a Rails pro

6条回答
  •  深忆病人
    2021-01-30 18:57

    I would bundle this all into the same app because you won't be duplicating the classes (models, plugins, etc.) across all the apps. Also: running 4 apps means that you'll have 4 processes all consuming memory due to the 4 separate Rails stacks they have loaded.

    Compiling it into one application eliminates this issue. For the issue between the sales site and the users site having to have different roots that can be solved, as mentioned earlier, by subdomain_fu. Let me expand with some sample code from an application I have:

    map.with_options :conditions => {:subdomain => 'logs'} do |admin|
      admin.resources :channels do |channel|
        channel.resources :logs
      end
      map.root :channels
      map.connect ':id', :controller => "channels", :action => "show"
    end
    

    As we see here, the :conditions for the with_options method sets :subdomain to be logs which means that anything coming in to logs.mysite.com will fufill these conditions and therefore be routed this way.

    Now further on in this routing file I have everything else wrapped up in a similar block:

    map.with_options :conditions => {:subdomain => nil} do |admin|
      # shebang!
    end
    

    Everything going to mysite.com will go to these routes.

    Lastly, compiling it all into one mega-super-hyper-app will eliminate the database-sharing issues.

提交回复
热议问题