lib/hobo/model_router.rb in hobo-0.8.5 vs lib/hobo/model_router.rb in hobo-0.8.6
- old
+ new
@@ -71,24 +71,27 @@
rescue
# No database, no routes
return
end
- require "#{RAILS_ROOT}/app/controllers/application" unless Object.const_defined? :ApplicationController
-
+ begin
+ require "#{RAILS_ROOT}/app/controllers/application" unless Object.const_defined? :ApplicationController
+ rescue MissingSourceFile => ex
+ # must be on Rails 2.3. Yay!
+ end
+
# Add non-subsite, and all subsite routes
[nil, *Hobo.subsites].each { |subsite| add_routes_for(map, subsite) }
add_developer_routes(map) if Hobo.developer_features?
- # Run the DRYML generators
- # TODO: This needs a proper home
- Hobo::Dryml::DrymlGenerator.run unless caller[-1] =~ /[\/\\]rake:\d+$/
rescue ActiveRecord::StatementInvalid => e
# Database problem? Just continue without routes
- ActiveRecord::Base.logger.warn "!! Database exception during Hobo routing -- continuing without routes"
- ActiveRecord::Base.logger.warn "!! #{e.to_s}"
+ if ActiveRecord::Base.logger
+ ActiveRecord::Base.logger.warn "!! Database exception during Hobo routing -- continuing without routes"
+ ActiveRecord::Base.logger.warn "!! #{e.to_s}"
+ end
end
def add_routes_for(map, subsite)
Hobo::ModelController.all_controllers(subsite, :force).each { |controller| ModelRouter.new(map, controller, subsite) }
@@ -130,15 +133,11 @@
model.name.underscore
end
def add_routes
- # Simple support for composite models, we might later need a CompositeModelController
- if model < Hobo::CompositeModel
- map.connect "#{plural}/:id", :controller => plural, :action => 'show', :requirements => ID_REQUIREMENT
-
- elsif controller < Hobo::ModelController
+ if controller < Hobo::ModelController
# index routes need to be first so the index names don't get
# taken as IDs
index_action_routes
lifecycle_routes if defined? model::Lifecycle
resource_routes
@@ -179,10 +178,10 @@
collection = collection_refl.name
owner_class = model.reflections[owner].klass.name.underscore
owner = owner.to_s.singularize if model.reflections[owner].macro == :has_many
- collection_path = "#{owner_class.pluralize}/:#{owner_class}_id/#{collection}"
+ collection_path = "#{owner_class.pluralize}/:#{owner}_id/#{collection}"
actions.each do |action|
case action
when :index
linkable_route("#{plural}_for_#{owner}", collection_path, "index_for_#{owner}",