Last active
August 29, 2015 14:02
-
-
Save almaron/d7da253e32115851f33f to your computer and use it in GitHub Desktop.
Jbuilder setting values in array loop
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
# Can I do something like this? | |
%w(text_field, another_text_field, some_more_text).each do |field| | |
json.field simple_format(@item.send(field.to_sym) | |
end | |
# Instead of this | |
json.text_field simple_format(@item.text_field) | |
json.another_text_field simple_format(@item.another_text_field) | |
json.some_more_text simple_format(@item.some_more_text) |
Ok. in case someone finds this gist.
The correct way to do this is as follows:
%w(whole bunch of text fields and even more).each do |field|
json.set! field, simple_format(@item.send(field)
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
?