Skip to content

Instantly share code, notes, and snippets.

View xuncheng's full-sized avatar
🎯
Focusing

Xuncheng Wang xuncheng

🎯
Focusing
View GitHub Profile

##Setup Textmate for Rails Dev on OS X

This guide was written by Jon Kinney for the Green Bay Ruby User Group. Jon works at Intridea and they graciously sponsor the Green Bay RUG meetings.

These guides were also partially completed using time from Intridea's SparkTime initiative which aims to give employees "outside projects" to work on during their normal work week.

If you find any issues with these suggestions please let me know. I've amassed these tips/tricks over several years of full time Rails development using Textmate but just because it works on my system doesn't always mean it will be problem free universally. Thanks to all the blog authors whose articles helped me learn Textmate over the years but whose links/posts I've lost or forgotten over time. If you have a cool Textmate tip or trick please post it in the comments!

@xuncheng
xuncheng / spec_has_many_through.rb
Created July 2, 2013 10:30
rspec testing has_many :through association
# video.rb
class Video < ActiveRecord::Base
has_many :categorizations
has_many :categories, through: :categorizations
end
# category.rb
class Category < ActiveRecord::Base
has_many :categorizations
has_many :videos, through: :categorizations
@xuncheng
xuncheng / application.html.erb
Created July 15, 2013 09:49
Rails default layout using bootstrap
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Rails Bootstrap" %></title>
<meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Rails Bootstrap" %>">
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
@xuncheng
xuncheng / application.html.haml
Created July 15, 2013 09:51
Rails default layout using bootstrap
!!!
%html
%head
%meta{:content => "width=device-width, initial-scale=1.0", :name => "viewport"}
%title= content_for?(:title) ? yield(:title) : "Rails Bootstrap"
%meta{:content => content_for?(:description) ? yield(:description) : "Rails Bootstrap", :name => "description"}
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
@xuncheng
xuncheng / _flash_messages.html.erb
Created July 15, 2013 09:52
Rails flash messages using bootstrap
<% flash.each do |name, msg| %>
<% if msg.is_a?(String) %>
<div class="alert alert-<%= name == :notice ? "success" : "error" %>">
<a class="close" data-dismiss="alert">&#215;</a>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
</div>
<% end %>
<% end %>
@xuncheng
xuncheng / _flash_messages.html.haml
Created July 15, 2013 09:53
Rails flash messages using bootstrap
- flash.each do |name, msg|
- if msg.is_a?(String)
%div{:class => "alert alert-#{name == :notice ? "success" : "error"}"}
%a.close{"data-dismiss" => "alert"} ×
= content_tag :div, msg, :id => "flash_#{name}"
@xuncheng
xuncheng / Gemfile
Created July 17, 2013 13:11
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.11'
gem 'haml-rails'
gem 'bootstrap-sass'
gem "bcrypt-ruby", "~> 3.0.1"
gem "bootstrap_form", "~> 1.0.0"
gem 'fabrication'
gem 'faker'
@xuncheng
xuncheng / macros.rb
Created July 22, 2013 06:17
user sign in using macors
def sign_in(a_user=nil)
user = a_user || Fabricate(:user)
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
@xuncheng
xuncheng / user_interact_with_queue_spec.rb
Created July 22, 2013 06:18
feature spec for user interacts with the queue
require 'spec_helper'
feature "User interact with the queue" do
scenario "User adds and reorders videos in the queue" do
comedies = Fabricate(:category)
monk = Fabricate(:video, title: "Monk", categories: [comedies])
south_park = Fabricate(:video, title: "South Park", categories: [comedies])
futurama = Fabricate(:video, title: "Futurama", categories: [comedies])
sign_in
@xuncheng
xuncheng / dom_element_find.js
Created January 2, 2014 14:02
Find the next or the previous instance for a given selected range
jQuery.fn.elementAfter = function(other) {
for(i = 0; i < this.length - 1; i++) {
if (this[i]() == other) {
return jQuery(this[i + 1]());
}
}
};
jQuery.fn.elementBefore = function(other) {
if (this.length > 0) {