Skip to content

Instantly share code, notes, and snippets.

rails g model reward campaign:references title amount:integer
rake db:migrate
  • in campaign model, set up the association and nested attributes
  • the reject_if: :all_blank will ignore this input(not throwing any validation error) if user didn't put in any value for this reward object
has_many :rewards, dependent: :destroy
# this enables us to create associated rewards models at the same time we're
@jennli
jennli / node.md
Last active March 16, 2016 22:12

Node

  • installation
npm install express --save
npm install -g express-generator
  • running the above commands should enable a express function:

CodeCore Day 42 - OAuth

Server --> Credentials --> Twitter Server <-- Tokens <-- Twitter Server --> Redirect --> Twitter Server <-- Info <-- Twitter

  • require a Gem
  • we're using gem: omniauth

Attach file

gem 'quiet_assets'
gem 'carrierwave'
bundle
rails g uploader Image

Simple form

  • gem
gem 'bootstrap-sass'
gem 'simple_form'
  • create a bootstrap_and_overrides.scss file, put in the following:
@import "bootstrap-sprockets";

Integration Test

  • brew install qt

  • gem 'capybara'

  • gem 'laundry'

  • create a features folder in rspec

 rails g rspec:feature campaigns
  • in rails_helper.rb, include capybara/rails as a required gem

Asynchronous Javascript and XML

how to make something with ajax?

  • form
<%= form_for [@question, @answer], remote: true do |f| %>
<div>
  <%= f.text_area :body %>
</div>
<%= f.submit %>

CSS Positioning strategies

  • inherit: use position value of container
  • static: normal layout (top left? default)
  • relative: offests from normal layout position
  • fixed: fixed position
  • absolute: offsets from the nearest container with a position attribute other than static

CSS Attributes

  • more convenient to use css method rather than updating the style using attr
@jennli
jennli / JQuery.md
Last active February 25, 2016 23:12

JQuery

  • makes managing DOM easier
  1. select elements
  2. manipulate selected elements
  3. add even listeners to selected elements
$('img').hide();
$('a').on('click', function(){console.log('that tickles')});