lib/pagelet_rails/concerns/controller.rb in pagelet_rails-0.1.8 vs lib/pagelet_rails/concerns/controller.rb in pagelet_rails-0.2.0
- old
+ new
@@ -58,11 +58,12 @@
pagelet_options(original_options: opts)
end
end
def pagelet_encoded_original_options new_opts = {}
- encode_data = pagelet_options.original_options.to_h.except('remote').merge(new_opts)
+ encode_data = pagelet_options.original_options.to_h
+ .with_indifferent_access.except('remote').deep_merge(new_opts)
PageletRails::Encryptor.encode(encode_data)
end
def pagelet_render_remotely?
case pagelet_options.remote
@@ -82,11 +83,25 @@
render_remotely
end
def redirect_to *args
- options = args.extract_options!
- new_params = options.merge(original_pagelet_options: pagelet_encoded_original_options)
+ begin
+ redirect_url = url_for(*args)
+ path_opts = Rails.application.routes.recognize_path(redirect_url)
+ rescue ActionController::RoutingError
+ return super
+ end
- render plain: pagelet(url_for(*args, new_params))
+ controller_class = path_opts[:controller].camelize.concat('Controller').safe_constantize
+ is_pagelet = controller_class && controller_class.include?(PageletRails::Concerns::Controller)
+
+ if is_pagelet
+ options = args.extract_options!
+ new_params = options.merge(original_pagelet_options: pagelet_encoded_original_options)
+
+ render plain: pagelet(url_for(*args, new_params))
+ else
+ super
+ end
end
end