Created
November 4, 2015 15:39
-
-
Save marinados/4b2c0e559e95dea3c708 to your computer and use it in GitHub Desktop.
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
gid = class_instance.to_global_id # method allowing to get a string with both model name and id | |
GlobalID::Locator.locate(gid) # method of getting the object by its global id (very useful for collections of multiple type of objects, e.g. for polymorphic associations) | |
Example : | |
In the model that has a polymorphic attribute detailable: | |
getter: | |
def global_detailable | |
detailable.to_global_id if detailable.present? | |
end | |
setter (for creation of a detailable as a nested attribute) | |
def global_detailable=(detailable) | |
self.detailable = GlobalID::Locator.locate(detailable) | |
end | |
view: | |
<%= f.grouped_collection_select :global_detailable, [@confirmed_sc_projects, @confirmed_projects], :all, :category_name, :to_global_id, :get_admin_details, include_blank: true %> | |
(grouped_collection_select allows to create groups of similar objects within a select) | |
array of different groups of possible select options | |
:all - method for select options (we're selecting all of them) | |
:category_name - optional name for groups of objects | |
:to_global_id - value method for the selected attribute | |
:get_admin_details - display method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment