Skip to content

Instantly share code, notes, and snippets.

@jennli
jennli / jade_.md
Last active February 23, 2016 19:06

Jade

  • allow to see logic behind HTML script
apm install atom-bootstrap3
apm install atom-jade
apm install preview-plus
  • index.jade
html
  • config/initializers
  • create a file called setup_mail.rb
ActionMailer::Base.smtp_settings = {
  address:              "smtp.gmail.com",
  port:                 "587",
  enable_starttls_auto: true,
  authentication:       :plain,
  user_name:            ENV["email_user_name"],
  password:             ENV["email_password"]

associate many to many through a third join model

  • generate the like model for awesome answers
rails g model like user:references question:references
rake db:migrate
  • go the question model to add in association:
  has_many :likes, dependent: :destroy
  has_many :users, through: :likes
  • to ensure migration runs for test environment
rake db:migrate RAILS_ENV=test

or

fundsy $ bin/rake db:test:prepare

Factory Girl

blog $ heroku create ldn-rails-blog

blog $ git remote -v

blog $ git push heroku master

blog $ heroku run rake db:migrate

USER AUTHENTICATION

password_digest

  • rails pre/append 'salt' before running through a hash algorithm
Digest::SHA1.digest("abcd1234")
"|\xE05\x9F\x12\x85\x7F*\x90\xC7\xDEF_@\xA9_\x01\xCB]\xA9"
2.2.3 :007 >
  • start by creating a user model

Resources

  • generate model and controller in one command
bin/rails g resource support_request name email message:text department done:boolean
  • quickly reset data
bin/rake db:drop db:create db:migrate db:seed
@jennli
jennli / git.md
Last active February 10, 2016 00:12

#Merge

  • git branch
  • git checkout -b feature/uniform_hellos
  • git status On branch feature/uniform_hellos
  • git diff master feature/uniform_hellos
  • git merge --abort
  • gitx
2.2.3 :006 > a.each do |x|
2.2.3 :007 >     puts x.body
2.2.3 :008?>   end
comment123
+----+------------+------------------------+-------------------------+---------+
| id | body       | created_at             | updated_at              | post_id |
+----+------------+------------------------+-------------------------+---------+
| 1  | comment123 | 2016-02-04 07:00:34... | 2016-02-04 07:47:09 UTC | 221     |
+----+------------+------------------------+-------------------------+---------+
@jennli
jennli / TDD.md
Last active March 16, 2016 17:48

#Test Driven Development

  • Write test cases before you write the code

###Test frameworks

  • UnitTest vs. RSpec
  • three phases: given , when, then

Gems and installation commands

  gem 'rspec-rails'