Guest User

Untitled

a guest
Mar 6th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. !!# routes
  2. ActionController::Routing::Routes.draw do |map|
  3. # Load site routes.
  4. # This also loads site db configurations to ActiveRecord::Base.configurations
  5. Site.add_routes_to map rescue nil
  6.  
  7. # Load Oyster routes
  8. map.with_options :conditions => {:host => "oyster.luckysneaks.com"} do |m|
  9. m.connect "/", :controller => "oyster", :action => "go_dashboard"
  10. m.logout "/logout", :controller => "sessions", :action => "destroy"
  11. m.resources :sessions, :collection => {:site => :put}
  12. m.resources :users
  13. m.resources :sites do |site|
  14. site.with_options :name_prefix => "site_" do |s|
  15. s.resources :entries, :member => {:publish => :put, :remove => :delete}, :collection => {:search => :get}
  16. s.resources :pages, :member => {:publish => :put, :remove => :delete}, :collection => {:search => :get}
  17. s.resources :comments, :member => {:moderate => :put}, :collection => {:search => :get}
  18. s.resources :categories, :collection => {:quick_add => :post}
  19. s.resources :tags
  20. # This route is wildly cheating at being RESTful, ie. it's not!
  21. s.resources :settings
  22. s.resources :sources
  23. end
  24. end
  25. end
  26. end
  27.  
  28. !!# model
  29. class Site < ActiveRecord::Base
  30. def self.add_routes_to(master)
  31. find(:all).each do |site|
  32. if site.routing.blank? or !site.is_active? or !File.exists?(site.directory_for(:app))
  33. master.with_options :controller => "actual_sites", :conditions => {:host => site.host} do |map|
  34. map.connect "/inactive", :action => "inactive" if !site.is_active?
  35. map.connect "/*whatever", :action => "catcher"
  36. end
  37. else
  38. master.with_options :controller => "#{site.db_name}_content", :conditions => {:host => site.host} do |map|
  39. site.routing.split("\n").each do |route|
  40. # Caveat: Malformed routes will not get added to the map!
  41. begin
  42. map.instance_eval(route)
  43. rescue
  44. logger.info "Malformed route '#{route}' not added!"
  45. end
  46. end
  47. end
  48. end
  49. unless ActiveRecord::Base.configurations.has_key? site.db_name
  50. config = ActiveRecord::Base.configurations[RAILS_ENV]
  51. ActiveRecord::Base.configurations[site.db_name] = {
  52. :adapter => "mysql",
  53. :host => config["host"],
  54. :username => config["username"],
  55. :password => config["password"],
  56. :database => "#{site.db}"
  57. }
  58. end
  59. end
  60. end
  61. end
Add Comment
Please, Sign In to add comment