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 / application_controller.rb
Created January 10, 2014 18:16
Redirect Problem
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter do
resource = controller_name.singularize.to_sym
method = "#{resource}_params"
params[resource] &&= send(method) if respond_to?(method, true)
end
@EminenceHC
EminenceHC / change_password.erb
Last active January 3, 2016 03:59
Custom devise method
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-vertical' }) do |f| %>
<%= devise_error_messages! %>
<%= f.input :password, :autocomplete => "off", label: 'New password' %>
<%= f.input :password_confirmation, label: 'Type your new password again' %>
<%= f.input :sign_in_count, :as => :hidden, :input_html => { :value => "2" } %>
<%= f.submit "Update", :class => "btn btn-primary" %>
<% end %>
@EminenceHC
EminenceHC / edit.html.erb
Created January 16, 2014 00:27
Same update method, different validation redirects
<%= simple_form_for @student, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.error_notification %>
<h4>Student Fields:</h4>
<%= f.input :case_no %>
<%= f.input :program %>
<%= f.input :admission_status %>
<%= f.input :temporary_password %>
<%= f.input :admission_date, as: :date_picker %>
@EminenceHC
EminenceHC / console_routes.rb
Created January 16, 2014 18:54
Custom update method routing problem.
edit_password_for_student_student GET /students/:id/edit_password_for_student(.:format) students#edit_password_for_student
PATCH /students/:id/edit_password_for_student(.:format) students#update_student_password
PUT /students/:id/edit_password_for_student(.:format) students#update_student_password
POST /students/:id/edit_password_for_student(.:format) students#update_student_password
@EminenceHC
EminenceHC / edit.html.erb
Last active January 3, 2016 12:19
Redirect to wrong controller.
<%= simple_form_for @student, :html => { :class => 'form-horizontal' } do |f| %>
<%= f.error_notification %>
<%= f.input :case_no, as: :hidden %>
<%= simple_fields_for @user do |u| %>
<h4>Change website and email passwords for <%= @user.full_name %></h4>
<%= u.error_notification %>
<div class="well">
<%= u.input :password, label: 'New Password' %>
<%= u.input :password_confirmation %>
<%#= u.hidden_field :cp, value: 'true' %>
@EminenceHC
EminenceHC / gist.xml
Last active January 4, 2016 18:09
XML to JSON post to students path
<message_list>
<message>
<message_id>2629</message_id>
<message_body>
<patient>
<case_no>14958</case_no>
<last_name>Marti</last_name>
<first_name>Pam</first_name>
<middle_name>P</middle_name>
<social_security_no>000000000</social_security_no>
@EminenceHC
EminenceHC / students_controller.rb
Last active August 29, 2015 13:55
Conditional .where on Social Security No
runquery = Student.joins(:user)
runquery = runquery.where(users: {first_name: params[:first_name]}) if params[:first_name].present?
runquery = runquery.where(users: {last_name: params[:last_name]}) if params[:last_name].present?
runquery = runquery.where(users: {loginable_id: params[:id]}) if params[:id].present?
runquery = runquery.where(program: params[:program]) if params[:program].present?
runquery = runquery.where(users: {social_security_no: '000000000'}) if params[:social_security_no] == 'no_social' # '000000000' || '' || '0'
runquery = runquery.select('students.*, students.id as sid, users.*')
@query = runquery
require 'daemons'
Daemons.run('notify_batch.rb')
Processing by StudentsController#index as HTML
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from index at /Users/travis.glover/RubymineProjects/eminence/app/controllers/students_controller.rb:82)
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."loginable_type" = 'Student'
Student Load (0.2ms) SELECT "students".* FROM "students" WHERE "students"."id" IN (1, 3, 51, 71, 74, 75, 76, 77, 78, 79, 80)
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from index at /Users/travis.glover/RubymineProjects/eminence/app/controllers/students_controller.rb:8
before_filter :fetch_user, only: :update
before_filter :activate, only: :update
def update
@student.update(student_params)
@user.update(user_params)
if @student.update(student_params) && @user.update(user_params)
redirect_to students_path, notice: "Student has been updated."