Skip to content

Instantly share code, notes, and snippets.

View qcam's full-sized avatar

Cẩm Huỳnh qcam

View GitHub Profile
@qcam
qcam / rvm-gemset.md
Created May 9, 2014 07:27
RVM Gemset commands

get gemset list

rvm gemset list

empty gemset

rvm getmset empty [gemset_name]
@qcam
qcam / heroku-config-sendgrid.md
Last active August 29, 2015 14:01
Mailer Configuration on Heroku

Heroku Mailer (SendGrid) configuration steps

  • Go to your heroku application.

  • Add SendGrid addons

  • Config STMP settings to your config/environment.rb

ActionMailer::Base.smtp_settings = {
@qcam
qcam / rails-active-record-pluck.md
Created May 12, 2014 08:23
[Active Record] How to get a single column's values into an array
User.where(:role => :admin).order(:username).pluck(:email)    #=> [admin1@example.com, admin2@example.com]
@qcam
qcam / rspec-anomyous_controller.md
Last active August 29, 2015 14:01
How to test anomyous controller with RSpec

In your logged_in_controller.rb

class LoggedInController < ApplicationController
  before_filter :authenticate_user!
end

In your logged_in_controller_spec.rb

@qcam
qcam / rails_admin-configuration.md
Created May 16, 2014 11:03
Rails admin field config

Rails Admin field configuration

rails_admin do
  list do
    field :customfield do
      def value
        bindings[:object].your_method
      end
    end
 end
class UrlValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    record.errors[attribute] << (options[:message] || "must be a valid URL") unless url_valid?(value)    
  end

  # a URL may be technically well-formed but may 
  # not actually be valid, so this checks for both.
  def url_valid?(url)
 url = URI.parse(url) rescue false
@qcam
qcam / capybara-wait_fo_ajax.md
Created May 20, 2014 02:38
Capybara - Wait for ajax to complete

##Capybara - Wait for ajax to complete

def wait_for_ajax
  Timeout.timeout(Capybara.default_wait_time) do
    loop do
      active = page.evaluate_script('jQuery.active')
      break if active == 0
    end
 end
@qcam
qcam / jquery-on_events.md
Last active August 29, 2015 14:01
jQuery event binding

The markup

<div id="parent">
  <a id="child">Click here please</a>
</div>

Instead of binding event this way this way

@qcam
qcam / rails-active_query.md
Created May 23, 2014 05:40
Rails Active Record Query

Rails Active Record Query

INNER JOIN

Category.joins(:posts)

# SELECT categories.* FROM categories INNER JOIN posts ON posts.category_id = categories.id
@qcam
qcam / rails-submit-button_18n.md
Created July 3, 2014 09:09
Rails Submit button I18n way

##Rails Submit button I18n way

en:
  helpers:
    submit:
      create: "Make New %{name}%"
      user:
        create: "Register"
 update: "Update Profile"