Skip to content

Instantly share code, notes, and snippets.

@wolfravenous
Last active October 5, 2016 15:19
Show Gist options
  • Save wolfravenous/b5a29376550c0115b27f7356befd5dcd to your computer and use it in GitHub Desktop.
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…
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
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
<p><%= @report.genderized_comment %></p>
<br>
<p> <%= @report.genderized_intro %></p>
<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