Skip to content

Instantly share code, notes, and snippets.

@wolfravenous
wolfravenous / model.rb
Last active October 5, 2016 15:19
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
@wolfravenous
wolfravenous / _form.html.erb
Created September 21, 2016 16:08
Scenario: two selectors both with days. User chooses Tuesday in one, Friday in the other. I need to assemble the days Tuesday through Friday as an array and display them all in the view. I store the selection data as first_day_id and last_day_id, but I can not figure out or find an example of how to assemble them as an array for the view.
<%= simple_form_for(report) do |f| %>
<%= f.input :first_day_id, collection: Week.all, as: :grouped_select, group_method: :days %>
<%= f.input :last_day_id, collection: Week.all, as: :grouped_select, group_method: :days %>
<%= f.button :submit, class: "btn-primary" %>
<% end %>
@wolfravenous
wolfravenous / ServerLogWhenWorking.log
Created September 20, 2016 14:29
Dynamic Selection boxes with jQuery fails on intial page load but works on page refresh
Started GET "/reports/new" for ::1 at 2016-09-20 10:29:29 -0400
Processing by ReportsController#new as HTML
Subject Load (0.2ms) SELECT "subjects".* FROM "subjects"
CACHE (0.0ms) SELECT "subjects".* FROM "subjects"
Intro Load (0.1ms) SELECT "intros".* FROM "intros" WHERE "intros"."subject_id" = ? [["subject_id", 1]]
Intro Load (0.1ms) SELECT "intros".* FROM "intros" WHERE "intros"."subject_id" = ? [["subject_id", 2]]
CACHE (0.0ms) SELECT "subjects".* FROM "subjects"
Unit Load (0.2ms) SELECT "units".* FROM "units" WHERE "units"."subject_id" = ? [["subject_id", 1]]
Unit Load (0.1ms) SELECT "units".* FROM "units" WHERE "units"."subject_id" = ? [["subject_id", 2]]
@wolfravenous
wolfravenous / _form.html.erb
Created September 20, 2016 13:09
Strange behavior when setting up Dynamic Boxes using JQuery and SimpleForm. When I navigate to the page the first time, the dynamic selection does not work. If I refresh the page in the browser then the dynamic selector works. Here is a gist of the relevant code. I tried installing the gem jQuery TurboLinks as suggested by a stack overflow post …
<%= simple_form_for(report) do |f| %>
<%= f.association :subject %>
<%= f.input :intro_id, collection: Subject.all, as: :grouped_select, group_method: :intros %>
<%= f.input :unit_id, collection: Subject.all, as: :grouped_select, group_method: :units %>
<%= f.button :submit, class: "btn-primary" %>
<% end %>
@wolfravenous
wolfravenous / RadioButtonFailure.html.erb
Created September 2, 2016 20:48
Rails Radio Button failing RSpec test with Gender can't Be Blank
ERB IN: app/view/new.html.erb
<p>
<%= radio_button_tag(:gender, "female") %>
<%= label_tag(:gender_female, "female") %>
<br>
<%= radio_button_tag(:gender, "male") %>
<%= label_tag(:gender_male, "male") %>
</p>
OUTPUT HTML ON: localhost:3000/reports/new