forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request activeadmin#5826 from activeadmin/fix_renamed_reso…
…urces_and_optional_belongs_to Fix renamed resources and optional `belongs_to`
- Loading branch information
Showing
7 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ActiveAdmin | ||
class Model | ||
def initialize(resource, record) | ||
@record = record | ||
|
||
if resource | ||
@record.extend(resource.resource_name_extension) | ||
end | ||
end | ||
|
||
def to_model | ||
@record | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
lib/active_admin/resource_controller/polymorphic_routes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "active_admin/resource" | ||
require "active_admin/resource/model" | ||
|
||
module ActiveAdmin | ||
class ResourceController < BaseController | ||
module PolymorphicRoutes | ||
def polymorphic_url(record_or_hash_or_array, options = {}) | ||
super(map_named_resources_for(record_or_hash_or_array), options) | ||
end | ||
|
||
def polymorphic_path(record_or_hash_or_array, options = {}) | ||
super(map_named_resources_for(record_or_hash_or_array), options) | ||
end | ||
|
||
private | ||
|
||
def map_named_resources_for(record_or_hash_or_array) | ||
return record_or_hash_or_array unless record_or_hash_or_array.is_a?(Array) | ||
|
||
record_or_hash_or_array.map { |record| to_named_resource(record) } | ||
end | ||
|
||
def to_named_resource(record) | ||
if record.is_a?(resource_class) | ||
return ActiveAdmin::Model.new(active_admin_config, record) | ||
end | ||
|
||
if record.is_a?(parent.class) | ||
return ActiveAdmin::Model.new(active_admin_config.belongs_to_config.resource, record) | ||
end | ||
|
||
record | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters