Last active
June 10, 2019 14:53
-
-
Save eLafo/106905c0b1e6d72722c401515de45502 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
class Foo | |
# Do some stuff... | |
# We want to update a field from another model with a value from this model | |
after_commit :update_bar_field | |
# Do more stuff... | |
private | |
def update_bar_field | |
# We want to update Bar#bar_field_2 with the value of Foo#foo_field_2 | |
# Bar and foo are related by bar_field_1 and foo_field_1 | |
# (yes, we might use associations instead, but this is an example ;-) ) | |
Bar.where(bar_field_1: foo_field_1).update(bar_field_2: foo_field_2) | |
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
class Foo | |
# Do some stuff... | |
# We want to update a field from another model with a value from this model | |
after_commit :update_bar_field | |
# Do more stuff... | |
private | |
def update_bar_field | |
# We want to update Bar#bar_field_2 with the value of Foo#foo_field_2 | |
# Bar and foo are related by bar_field_1 and foo_field_1 | |
# (yes, we might use associations instead, but this is an example ;-) ) | |
Bar.by_bar_field_1(foo_field_1).update(bar_field_2: foo_field_2) | |
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
class Foo | |
include Wisper::Publisher | |
# Do some stuff... | |
# We want to update a field from another model with a value from this model | |
after_commit -> (foo) { foo.broadcast(:foo_saved, foo.foo_field) } | |
end | |
class Bar | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment