forked from carlosantoniodasilva/i18n_alchemy
-
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.
Adding support to custom association parser.
With this, we fix carlosantoniodasilva#18.
- Loading branch information
Cairo Noleto
committed
Jun 13, 2012
1 parent
bbd8478
commit 6420853
Showing
7 changed files
with
66 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class MyCustomAssociationParser < I18n::Alchemy::AssociationParser | ||
def parse(attributes) | ||
if association.options[:polymorphic] | ||
@proxy = target_class.i18n_alchemy_proxy.localized | ||
end | ||
|
||
super | ||
end | ||
|
||
def self.localize(object) | ||
object | ||
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
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,3 @@ | ||
class Company < ActiveRecord::Base | ||
include I18n::Alchemy | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Person < ActiveRecord::Base | ||
include I18n::Alchemy | ||
localize :personable, :using => MyCustomAssociationParser | ||
|
||
belongs_to :personable, :polymorphic => true | ||
|
||
accepts_nested_attributes_for :personable | ||
|
||
def build_personable(attributes, options = {}) | ||
self.personable = personable_type.constantize.new(attributes, options) | ||
end | ||
|
||
def self.i18n_alchemy_proxy | ||
Company.new | ||
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