Skip to content

Instantly share code, notes, and snippets.

View EminenceHC's full-sized avatar

EminenceHC EminenceHC

  • Eminence Healthcare
  • Fresno CA
View GitHub Profile
@EminenceHC
EminenceHC / case_management.rb
Last active November 20, 2015 20:01
On an edit page, attach additional fields_for to a nested objec
class CaseManagement < ActiveRecord::Base
has_one :service, as: :serviceable
has_many :treatment_plan_problems, dependent: :destroy
accepts_nested_attributes_for :treatment_plan_problems, allow_destroy: true
validates_associated :treatment_plan_problems
end
@EminenceHC
EminenceHC / foo.js
Last active October 1, 2015 16:22
select options from array
// I am using ajax to get an array of values which I want to turn into select options.
// When I log my array to console this is what I get:
Array[2], each item in the array looks like this:
Array[2]
0: "Abstain from substance abuse and participate in a recovery-based program."
1: 1
1: Array[2]
0: "Engage in healthy, safe alternative activities to substance abuse that do not cause cognitive, behavioral, or emotional changes."
@EminenceHC
EminenceHC / foo.js
Created October 1, 2015 16:09
Parse key value pair into select option
// In the console log I can see that
$(".desc-trigger").each(function() {
if ($(this).val == "1"){$(this).closest('.parent').find('.desc').show();}
else {$(this).closest('.parent').find('.desc').hide();}
});
@EminenceHC
EminenceHC / school.rb
Created July 20, 2015 18:54
Dynamically
def self.get_group_times(school_id, group_number)
school = School.find(school_id)
var = group_number.to_i
return school."g#{var}start" # I need this to not be a string value it should be: school.g1start
end
@EminenceHC
EminenceHC / controller.rb
Created June 15, 2015 22:12
PDF stylesheet
def show
@intake_agreement = IntakeAgreement.find(params[:id])
respond_to do |format|
format.html do
render layout: 'pdf'
end
format.pdf do
render pdf: 'filename',
layout: 'pdf',
[root@ip-50-62-74-70 httpdocs]# RAILS_ENV=production rails console
/var/www/vhosts/eminencehc.net/httpdocs/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/core_ext/object/try.rb:45:in `round': NaN (FloatDomainError)
from /var/www/vhosts/eminencehc.net/httpdocs/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/core_ext/object/try.rb:45:in `public_send'
from /var/www/vhosts/eminencehc.net/httpdocs/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/core_ext/object/try.rb:45:in `try'
from /var/www/vhosts/eminencehc.net/httpdocs/app/models/missing_client_tests_calculation.rb:26:in `block in <class:MissingClientTestsCalculation>'
from /var/www/vhosts/eminencehc.net/httpdocs/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation/delegation.rb:13:in `each'
from /var/www/vhosts/eminencehc.net/httpdocs/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/relation/delegation.rb:13:in `each'
from /var/www/vhosts/eminencehc.
@EminenceHC
EminenceHC / if.html.erb
Created April 2, 2015 17:15
If statement inside another if statement?
if a.one == 1
if foo.one == 1 || foo.two == 1 || foo.three == 1
else
if bar.one == 1 || bar.two == 1 || bar.three == 1
end
# Do something
else
# Do something else
end
@EminenceHC
EminenceHC / reviews_controller.rb
Created March 25, 2015 18:29
Query Optimization
@reviews = Review.all
@EminenceHC
EminenceHC / form.html.erb
Created March 11, 2015 17:17
Default value if param present?
<% if params[:referral_id].present? %>
<%= f.input :referral_id, input_html: {value: params[:referral_id]} %>
<% else %>
<%= f.input :referral_id %>
<% end %>