Wednesday, September 30, 2015

rake task to delete orphan quiz records


# encoding: utf-8

namespace :db do
  desc "delete orphan quizzes"
  task delete_orphan_quizzes: :environment do
    # now = Time::now
    # Quiz.where(has_been_graded:false, mode:'quiz').each do |quiz|
    #   if quiz.expiretime.nil? || now > quiz.expiretime
    #     quiz.destroy
    #   end
    # end

    # alternate strategy, using delete (destroy instantiates ActiveRecord objects and is slow)
    # TODO: probably better to use batches here?
    # hardcoded limit of 1000 at the moment
    ids = Quiz.where("has_been_graded = ? AND mode = ? AND expiretime < ?", false, "quiz", Time::now).limit(1000).pluck :id
    puts "ids=#{ids}"
    # delete quiz and dependent objects (just ungraded questions since these quizzes have not been graded)
    Quiz.delete_all(id:ids)
    QuizQuestionMapping.delete_all(quiz_id:ids)
  end
end



ruby one-liner to print server time



ruby -e 'puts Time::now'


pwo sql to examine quizzes in progress (ungraded, unexpired)


SELECT * FROM `quizzes` WHERE (has_been_graded = 0 AND mode = 'quiz' AND expiretime > NOW())

SELECT * FROM `quizzes` WHERE (has_been_graded = 0 AND expiretime > NOW())

rails destroy vs delete_all association performance

http://stackoverflow.com/questions/2797339/rails-dependent-destroy-vs-dependent-delete-all


##################################################
# destroy
##################################################
1.9.3-p286 :004 > Quiz.last.destroy
  Quiz Load (0.3ms)  SELECT `quizzes`.* FROM `quizzes` ORDER BY `quizzes`.`id` DESC LIMIT 1
   (0.1ms)  BEGIN
  QuizQuestionMapping Load (0.4ms)  SELECT `quiz_question_mappings`.* FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`quiz_id` = 264613
  SQL (0.3ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28891
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28892
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28893
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28894
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28895
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28896
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28897
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28898
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28899
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28900
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28901
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28902
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28903
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28904
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28905
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28906
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28907
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28908
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28909
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28910
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28911
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28912
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28913
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28914
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28915
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28916
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28917
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28918
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28919
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28920
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28921
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28922
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28923
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28924
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28925
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28926
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28927
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28928
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28929
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28930
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28931
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28932
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28933
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28934
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28935
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28936
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28937
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28938
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28939
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28940
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28941
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28942
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28943
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28944
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28945
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28946
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28947
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28948
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28949
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28950
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28951
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28952
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28953
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28954
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28955
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28956
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28957
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28958
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28959
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28960
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28961
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28962
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28963
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28964
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28965
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28966
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28967
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28968
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28969
  SQL (0.2ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28970
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28971
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28972
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28973
  SQL (49.7ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28974
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28975
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28976
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28977
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28978
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28979
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28980
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28981
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28982
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28983
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28984
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28985
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28986
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28987
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28988
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28989
  SQL (0.1ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`id` = 28990
  GradedQuizQuestionMapping Load (0.2ms)  SELECT `graded_quiz_question_mappings`.* FROM `graded_quiz_question_mappings` WHERE `graded_quiz_question_mappings`.`quiz_id` = 264613
  SQL (0.2ms)  DELETE FROM `quizzes` WHERE `quizzes`.`id` = 264613
   (0.4ms)  COMMIT



##################################################
# delete_all
##################################################
1.9.3-p286 :001 > Quiz.last.destroy
  Quiz Load (0.2ms)  SELECT `quizzes`.* FROM `quizzes` ORDER BY `quizzes`.`id` DESC LIMIT 1
   (0.1ms)  BEGIN
  SQL (1.0ms)  DELETE FROM `quiz_question_mappings` WHERE `quiz_question_mappings`.`quiz_id` = 264612
  GradedQuizQuestionMapping Load (0.2ms)  SELECT `graded_quiz_question_mappings`.* FROM `graded_quiz_question_mappings` WHERE `graded_quiz_question_mappings`.`quiz_id` = 264612
  SQL (0.3ms)  DELETE FROM `quizzes` WHERE `quizzes`.`id` = 264612
   (0.6ms)  COMMIT
 => #<Quiz id: 264612, name: "Flight Instructor, Airplane", minutes_allowed: 150, mode: "quiz", has_been_graded: false, curidx: 0, starttime: "2015-09-29 18:35:38", stoptime: nil, expiretime: "2015-09-29 21:05:38", score: nil, source: "choose-quiz", is_instructor_quiz: false, template_id: 0, user_id: 1, product_id: 6, quiz_definition_id: 8, created_at: "2015-09-29 18:35:38", updated_at: "2015-09-29 18:35:39"> 

Wednesday, September 23, 2015

notes on migrating pws2013rails to rails 4.2.2

upgrade to 4.2.2


rvm gemset create pws2013
rvm use ruby-2.2.2@pws2013
echo "ruby-2.2.2" > .ruby-version
echo "pws2013" > .ruby-gemset


change gem file to be based on sample app 3e
bundle
whines about gem lock
bundle update


##################################################
# whitelist_attributes 
##################################################
Exiting
/Users/smr/.rvm/gems/ruby-2.2.2@pwo222test/gems/activerecord-4.2.2/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `whitelist_attributes=' for ActiveRecord::Base:Class (NoMethodError)

https://github.com/rails/protected_attributes/issues/5

comment out:
config.active_record.whitelist_attributes = true
in /Users/smr/Desktop/pwo222test/pws2013rails/config/application.rb


##################################################
# mass_assignment_sanitizer 
##################################################
/Users/smr/.rvm/gems/ruby-2.2.2@pwo222test/gems/activerecord-4.2.2/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `mass_assignment_sanitizer=' for ActiveRecord::Base:Class (NoMethodError)

coment out:
config.active_record.mass_assignment_sanitizer = :strict
in:
/Users/smr/Desktop/pwo222test/pws2013rails/config/environments/development.rb
/Users/smr/Desktop/pwo222test/pws2013rails/config/environments/test.rb


##################################################
# auto_explain_threshold_in_seconds 
##################################################
/Users/smr/.rvm/gems/ruby-2.2.2@pwo222test/gems/activerecord-4.2.2/lib/active_record/dynamic_matchers.rb:26:in `method_missing': undefined method `auto_explain_threshold_in_seconds=' for ActiveRecord::Base:Class (NoMethodError)

comment out:
config.active_record.auto_explain_threshold_in_seconds = 0.5


##################################################
# `match` method in your router 
##################################################
/Users/smr/.rvm/gems/ruby-2.2.2@pwo222test/gems/actionpack-4.2.2/lib/action_dispatch/routing/mapper.rb:238:in `add_request_method': You should not use the `match` method in your router without specifying an HTTP method. (ArgumentError)
If you want to expose your action to both GET and POST, add `via: [:get, :post]` option.
If you want to expose your action to GET, use `get` in the router:
  Instead of: match "controller#action"
  Do: get "controller#action"

tweak routes.rb


##################################################
# Unknown key: :select 
##################################################
ArgumentError (Unknown key: :select. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type):

http://stackoverflow.com/questions/22750091/block-in-assert-valid-keys-unknown-key-order-argumenterror

change:
  has_many :instructors, :through => :followed_instructors,
           :select => "users.*, instructor_student_affiliations.pending AS pending"
to:
http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many

rework like this:
  # rails 4 no likey
  # has_many :instructors, :through => :followed_instructors,
  #          :select => "users.*, instructor_student_affiliations.pending AS pending"
  has_many :instructors, 
            -> { select("users.*, instructor_student_affiliations.pending AS pending") }, 
            :through => :followed_instructors


##################################################
# undefined method `attr_accessible' 
##################################################
NoMethodError (undefined method `attr_accessible' for #<Class:0x007fd499c2a8b0>):

comment these out

***N.B. will likely have to tweak ledermann/rails-settings
class UserSettingsObject < RailsSettings::SettingObject
  # with rails 3.2
  # :var and :target need to be accessible to read values
  # if you want to change values they also need to be accessible
  # attr_accessible :var, :target, :should_send_test_completed_emails, :quiz_in_progress
  # https://github.com/ledermann/rails-settings/issues/65
end


##################################################
# compass
##################################################
File to import not found or unreadable: compass

not using this anymore. comment it out.
/Users/smr/Desktop/pwo222test/pws2013rails/app/assets/stylesheets/application.css.scss:
// @import "compass";


##################################################
# Extra .css in SCSS file 
##################################################
DEPRECATION WARNING: Extra .css in SCSS file is unnecessary.

rename these


##################################################
# @extend ".control-group" 
##################################################
Sass::SyntaxError (".field_with_errors" failed to @extend ".control-group".
The selector ".control-group" was not found.
Use "@extend .control-group !optional" if the extend should be able to fail.
):
  app/assets/stylesheets/main.scss:71
  app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__4553874112999930212_70265466688080'

https://github.com/plataformatec/simple_form


##################################################
# comment out all attr_accessible 
##################################################


##################################################
# scope needs to be callable 
##################################################
http://stackoverflow.com/questions/28951671/argument-error-the-scope-body-needs-to-be-callable

change to something like:
  scope :graded, -> { where(has_been_graded:true).order("stoptime DESC") }


##################################################
# sql error 
##################################################

ActiveRecord::StatementInvalid (Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*, instructor_student_affiliations.pending AS pending) FROM `users` INNER JOIN `' at line 1: SELECT COUNT(users.*, instructor_student_affiliations.pending AS pending) FROM `users` INNER JOIN `instructor_student_affiliations` ON `users`.`id` = `instructor_student_affiliations`.`instructor_id` WHERE `instructor_student_affiliations`.`student_id` = 1):
  app/models/user.rb:230:in `student?'
  app/models/user.rb:243:in `school_roles'
  app/views/users/show.html.erb:28:in `_app_views_users_show_html_erb__1110688672353824995_70241578162000'

not totally sure what's going on here

  def student?
    # return instructors.count > 0   #causing weird mysql error
    return instructors.length > 0
  end


##################################################
# [POST] "/init_quiz" 
##################################################
ActionController::RoutingError (No route matches [POST] "/init_quiz"):


##################################################
# none scope 
##################################################
You tried to define a scope named "none" on the model "Question", but Active Record already defined a class method with the same name.


##################################################
# multiline anchors 
##################################################
The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?

http://stackoverflow.com/questions/17759735/regular-expressions-with-validations-in-ror-4

se \A and \z rather than ^ and $ because in Ruby, ^ and $ match only a newline not start and end of string, which allows a javascript exploit to pass the test. 


##################################################
# replace modal hide 
##################################################


##################################################
# scoped 
##################################################
use User.all instead.

    else
      User.all
    end


##################################################
# ActiveModel::ForbiddenAttributesError 
##################################################
ActiveModel::ForbiddenAttributesError in UsersController#update
try to edit user
error
http://guides.rubyonrails.org/action_controller_overview.html#strong-parameters

need to:
add a private permit method to the controller
  private
    # Using a private method to encapsulate the permissible parameters
    # is just a good pattern since you'll be able to reuse the same
    # permit list between create and update. Also, you can specialize
    # this method with per-user checking of permissible attributes.
    def school_params
      params.require(:school).permit(:name, :actcode)
    end

  and do this in the update call:
    respond_to do |format|
      # if @school.update_attributes(params[:school])
      if @school.update_attributes(school_params)
        format.html { redirect_to @school, notice: 'School was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @school.errors, status: :unprocessable_entity }
      end



deal:
DEPRECATION WARNING: Passing a nested array to Active Record finder methods is deprecated and will be removed. Flatten your array before using it for 'IN' conditions. (called from search at /Users/smr/Desktop/pwo222test/pws2013rails/app/models/user.rb:294)





##################################################
# simple_form 3.2 
##################################################
https://github.com/plataformatec/simple_form

run this:
rails generate simple_form:install --bootstrap


diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index 3a37025..2374383 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -10,29 +10,7 @@ en:
       # html: '<abbr title="required">*</abbr>'
     error_notification:
       default_message: "Please review the problems below:"
-    labels:
-      defaults:
-        actcode: 'Activation Code'
-      custom_question:
-        actcode: 'Activation Code'
-        answerA: 'Answer A'
-        answerB: 'Answer B'
-        answerC: 'Answer C'
-        correctChoice: 'Correct Choice'
-      school:
-        name: 'School Name'
-      score_submission:
-        mail_street_address: 'Street'
-        mail_city: 'City'
-        mail_state: 'State'
-        mail_zip: 'Zip'
-        mail_country: 'Country'
-      subscription:
-        actcode: 'Activation Code'
-
-
-
-    # Labels and hints examples
+    # Examples
     # labels:
     #   defaults:
     #     password: 'Password'
@@ -45,4 +23,9 @@ en:
     #   defaults:
     #     username: 'User name to sign in.'
     #     password: 'No special characters, please.'
-
+    # include_blanks:
+    #   defaults:
+    #     age: 'Rather not say'
+    # prompts:
+    #   defaults:
+    #     age: 'Select your age'


##################################################
# simple_form horizontal form 
##################################################
<% provide(:title, "Sign In") %>
<div class="row">
  <div>
    <h2>Sign In</h2>
    <%= simple_form_for :session, url: sessions_path, 
      html: { class: 'form-horizontal' },
      wrapper: :horizontal_form,
      wrapper_mappings: {
        check_boxes: :horizontal_radio_and_checkboxes,
        radio_buttons: :horizontal_radio_and_checkboxes,
        file: :horizontal_file_input,
        boolean: :horizontal_boolean
      } do |f| %>
      <%= f.input :email %>
      <%= f.input :password %>
      <%= f.button :submit, 'Sign In', :class => 'btn' %>
    <% end %>

    <p><%= link_to 'Forgot password?', new_password_reset_path %></p>

  </div>
</div>




##################################################
# rework test database 
##################################################
create database pws2013Test;
GRANT ALL PRIVILEGES ON pws2013Test .* TO pws2013TestUser@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON pws2013Test .* TO pws2013TestUser@'localhost' IDENTIFIED BY 'password';
show grants for pws2013TestUser;


rake db:migrate RAILS_ENV=test


##################################################
# guard doesn't seem to be running the tests 
##################################################
https://github.com/guard/guard-minitest/issues/114
spring: 'bundle exec spring rake test' works
but spring: true does not work.
It's because bin/rake doesn't exist...

https://github.com/rails/spring
bundle exec spring binstub --all


http://stackoverflow.com/questions/32215922/rails-4-guard-is-not-part-of-the-bundle-add-it-to-gemfile-gemloaderror

  gem 'guard'
  gem 'guard-minitest',     '2.4.4'

[smr@smr pws2013 (migrate-to-rails4 *%)]$ bundle exec guard
17:46:49 - INFO - Guard::Minitest 2.4.4 is running, with Minitest::Unit 5.8.0!
17:46:49 - INFO - Guard is now watching at '/Users/smr/current_projects/prepware-school-2013/pws2013'


# spec folder interferes with guard run all 
##################################################
***For some reason this issue occurs if there is spec folder along with the test one. I was migrating from rspec to minitest and I was trying to solve this issue but I gave up. Anyway, as soon as I renamed the spec folder the issue was fixed... weird.


##################################################
# spring and guard
##################################################
1. run all tests
run guard and hit return to run all the tests (since we are using all_on_start: false).


[smr@smr pws2013 (migrate-to-rails4 *%)]$ bundle exec guard
20:16:15 - INFO - Guard::Minitest 2.4.4 is running, with Minitest::Unit 5.8.0!
20:16:15 - INFO - Guard is now watching at '/Users/smr/current_projects/prepware-school-2013/pws2013'
[1] guard(main)> 
20:16:16 - INFO - Run all
20:16:16 - INFO - Running: all tests
Started

  2/2: [===================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.29143s
2 tests, 5 assertions, 0 failures, 0 errors, 0 skips

2. run a file's tests by saving it (see guard file fr rules on what tests get run when certain files are saved)

20:22:27 - INFO - Running: test/integration/site_layout_test.rb
Started

  1/1: [===================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.33901s
1 tests, 4 assertions, 0 failures, 0 errors, 0 skips




install spring stubs:
[smr@smr pws2013 (migrate-to-rails4 *%)]$ bundle exec spring binstub --all
* bin/rake: spring already present
* bin/rails: spring already present


[smr@smr pws2013 (migrate-to-rails4 *%)]$ spring status
Spring is running:

54829 spring server | pws2013 | started 2 hours ago                                                     
54830 spring app    | pws2013 | started 2 hours ago | test mode  

[smr@smr pws2013 (migrate-to-rails4 *%)]$ spring stop
Spring stopped.
[smr@smr pws2013 (migrate-to-rails4 *%)]$ spring status
Spring is not running.

can also check for spring processes using
[smr@smr pws2013 (migrate-to-rails4 *%)]$ ps aux | grep spring


##################################################
# secret_key_base 
##################################################
/Users/smr/current_projects/prepware-school-2013/pws2013/config/secrets.yml

N.B. for production server
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>




























Tuesday, September 22, 2015

check rails log level




1.9.3-p286 :001 > Rails.configuration.log_level
 => :debug 
The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown, corresponding to the log level numbers from 0 up to 5 respectively. To change the default log level, use

config.log_level = :warn # In any environment initializer, or
Rails.logger.level = 0 # at any time



appname/config/environments/production.rb

  # See everything in the log (default is :info) The available log levels are:
  # :debug, :info, :warn, :error, :fatal, and :unknown, corresponding to the
  # log level numbers from 0 up to 5 respectively.
  config.log_level = :warn


Thursday, September 10, 2015

notes on running pws2013rails using ruby 2.2.2

pow222test
http://srouse@util.prepwareschool.com/stash/scm/PS13/pws2013rails.git
rvm gemset create pwo222test
rvm use 2.2.2@pwo222test
echo "ruby-2.2.2" > .ruby-version
echo "pwo222test" > .ruby-gemset

cd-ing into the directory switches the ruby and gemset:
[smr@smr pwo222test]$ rvm current
ruby-1.9.3-p286
[smr@smr pwo222test]$ cd pws2013rails/
[smr@smr pws2013rails (master %)]$ rvm current
ruby-2.2.2@pwo222test

gem install bundler
bundle

##################################################
# error - bundler gem
##################################################
∆ to gem 'bigdecimal', '1.2.6'
Using bigdecimal 1.2.6 (was 1.1.0)

##################################################
# error - json
##################################################
An error occurred while installing json (1.7.7), and Bundler cannot continue.
∆ to gem 'json', '1.8.3'
You have requested:
  json = 1.8.3

The bundle currently has json locked at 1.7.7.
Try running `bundle update json`
bundle update json

##################################################
# error - mysql2
##################################################
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
bundle update mysql2

get this again:
You have requested:
  json = 1.8.3
looks like bundle update json didn't complete due to the mysql2 error
manually edit
json (1.8.3)
in /Users/smr/Desktop/pwo222test/pws2013rails/Gemfile.lock

bundle update mysql2
Installing mysql2 0.4.0 (was 0.3.11) with native extensions
change:
gem 'mysql2', '0.4.0'

##################################################
# error - sqlite3
##################################################
An error occurred while installing sqlite3 (1.3.7), and Bundler cannot continue.
bundle update sqlite3
Installing sqlite3 1.3.10 (was 1.3.7) with native extensions
change:
gem 'sqlite3', '1.3.10'

##################################################
# error - therubyracer
##################################################
change
gem 'therubyracer', :platforms => :ruby
bundle

Installing libv8 3.16.14.11 (was 3.3.10.4)
Installing ref 2.0.0
Installing therubyracer 0.12.2 (was 0.10.2) with native extensions
Installing uglifier 1.3.0
Bundle updated!



sss
/Users/smr/.rvm/gems/ruby-2.2.2@pwo222test/gems/activesupport-3.2.7/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
/Users/smr/.rvm/gems/ruby-2.2.2@pwo222test/gems/bundler-1.10.6/lib/bundler/rubygems_integration.rb:302:in `block in replace_gem': Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (can't activate mysql2 (~> 0.3.10), already activated mysql2-0.4.0. Make sure all dependencies are added to Gemfile.) (LoadError)

add:
gem 'activerecord-mysql2-adapter'
Installing activerecord-mysql2-adapter 0.0.3
error on page load
http://stackoverflow.com/questions/12730190/rails-mysql2-undefined-method-accept-for-nilnilclass
[smr@smr pws2013rails (master *%)]$ gem list | grep 'mysql'
activerecord-mysql2-adapter (0.0.3)
mysql2 (0.4.0)


http://stackoverflow.com/questions/9862080/rails-3-2-2-mysql2-adapter-error
change
# gem 'mysql2'
gem "mysql2", "~> 0.3.11"


app starts now
##################################################
# error - jquery not defined
##################################################
Uncaught ReferenceError: jQuery is not defined
http://stackoverflow.com/questions/15577610/jquery-not-loading-jquery-rails-2-2-1-rails-3-2-1
gem 'rails', '3.2.13'
gem 'rack', '1.4.5'

bundle update rack
bundle update rails
succeeds
app starts
##################################################
# error - undefined method `name' for nil:NilClass
##################################################
grade quiz. undefined method `name' for nil:NilClass

commenting this line out gets rid of the problem.
      # now that we've moved them to the graded table, zap the qqms
      # quiz_question_mappings.clear()

http://stackoverflow.com/questions/29409323/ror-nomethoderror-when-executing-delete-all-for-a-has-many-relationship

This is the Rails issue with Ruby 2.2.2: https://github.com/rails/rails/issues/18991 . It's closed and fixed in 3.2.22).

gem 'rails', '3.2.22'
bundle update rails

appears to fix the issue.


##################################################
# working gem file
##################################################
source 'https://rubygems.org'

# gem 'rails', '3.2.21'
gem 'rails', '3.2.22'  #the last v3 release. https://rubygems.org/gems/rails/versions
gem 'rack', '1.4.5'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3', '1.3.10'
# gem 'mysql2'
gem "mysql2", "~> 0.3.11"
gem 'bigdecimal', '1.2.6'
# gem 'bootstrap-sass', '~> 2.1.1.0'
gem 'bootstrap-sass', '2.3.1.2'
gem 'simple_form'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'rb-readline'
gem 'rubyzip'
gem 'nokogiri', '1.5.9'
gem 'ledermann-rails-settings'
gem 'json', '1.8.3'

group :development, :test do
  gem 'childprocess', '0.3.6'  #https://github.com/guard/guard-spork/issues/107
  gem 'rspec-rails', '2.11.0'
  gem 'guard-rspec', '1.2.1'
  gem 'guard-spork', '1.2.0'
  gem 'spork', '0.9.2'
end

group :development do
  gem "rails-erd"
end

group :test do
  gem 'capybara', '1.1.2'
  gem 'factory_girl_rails', '1.4.0'
  gem 'launchy'
  # System-dependent gems
  # Test gems on Macintosh OS X
  gem 'rb-fsevent', '0.9.1', :require => false
  gem 'growl', '1.0.3'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', '0.10.2', :platforms => :ruby
  gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
  gem 'compass-rails'
end

gem 'jquery-rails'
gem 'prawn'
gem 'rails-xmlrpc'

# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
gem 'capistrano'

# To use debugger
# gem 'debugger'



Monday, September 7, 2015

imac27 SSD upgrade - SSD Fan Control


replaced HD with 500G samsung evo.
known issue: hd cooling fan runs fast after drive replacement.

http://exirion.net/ssdfanctrl/




iMac users who tweak their systems using 3rd party hard disks or solid state disks, are often surprised by an unpleasant aftermath: an annoyingly noisy hard disk fan. Fan management in Apple systems relies on temperatures reported by the SMC system. The SMC collects data from external sensors or by reading the internal hard disk temperature in a proprietary manner. Sometimes reusing the external sensor is not possible or, as in more recent generations of iMacs, replacing the original hard disk breaks the system’s temperature monitoring.  In both cases the SMC system tends to go into frenzy and drive you mad with a loud fan.