Last active
October 5, 2016 15:19
-
-
Save wolfravenous/b5a29376550c0115b27f7356befd5dcd to your computer and use it in GitHub Desktop.
Need to move Logic From the View into The Model, Rails v. 4.2, The current entry in the model for setting the gender in comments, works correctly because comment is an attribute of report. Would like to move the logic currently in the view to the model, however I am unsure of how to because content is an attribute of intro, which is a nested res…
This file contains hidden or 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
after_validation :set_g_comment | |
# | |
protected | |
# | |
def set_g_comment | |
if self.gender == "female" | |
self.comment=self.comment.gsub("HESHE","she".capitalize) | |
else | |
self.comment=self.comment.gsub("HESHE","he".capitalize) | |
end | |
end |
This file contains hidden or 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
def gender_pronoun | |
gender == 'female' ? 'she' : 'he' | |
end | |
def genderized_comment | |
comment.gsub(/HESHE/, gender_pronoun.capitalize) | |
end | |
def genderized_intro | |
intro.content.gsub(/HESHE/, gender_pronoun.capitalize) | |
end |
This file contains hidden or 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
<p><%= @report.genderized_comment %></p> | |
<br> | |
<p> <%= @report.genderized_intro %></p> |
This file contains hidden or 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
<p> | |
<% if @report.gender=="female" | |
@report.intro.content=@report.intro.content.gsub("HESHE","she".capitalize) | |
else | |
@report.intro.content=@report.intro.content.gsub("HESHE","he".capitalize) | |
end %> | |
<%= @report.intro.content %> | |
</p> | |
<p><%= @report.comment %></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment