Skip to content

Instantly share code, notes, and snippets.

Using jQuery

jQuery has become the most popular JavaScript library both inside and outside the Rails community. Let's look at how to take advantage of the library with our applications.

Setup

The setup process differs depending on whether your app is running on a version of Rails before 3.1 or greater than 3.1.

Before Rails 3.1: jquery-rails

@mhriess
mhriess / friendly_urls.markdown
Created November 13, 2012 19:17 — forked from agnellvj/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@mhriess
mhriess / card.rb
Created October 25, 2012 04:38 — forked from dbc-challenges/card.rb
FlashCardinator
class Session
attr_reader :output_stream
def initialize(game, input_stream = $stdin, output_stream = $stdout)
@game = game
@input_stream = input_stream
@output_stream = output_stream
end
require 'simplecov'
SimpleCov.start
require './binary_search.rb'
describe "#binary_search" do
let(:array_1) { [1,2,3,4,5,6,7] }
let(:array_2) { ["apple", "pear", "banana", "pineapple", "kiwi"].sort}
it "is defined as a method" do
@mhriess
mhriess / card.rb
Created October 18, 2012 19:11 — forked from dbc-challenges/card.rb
FlashCardinator
require 'csv'
require 'term/ansicolor'
# Use this trick to work around namespace cluttering that
# happens if you just include Term::ANSIColor:
class Color
extend Term::ANSIColor
end
# Put your answers here!
Michael-Riess-Computer:sample_project michaelriess$ rvm list
rvm rubies
ruby-1.8.7-p302 [ i686 ]
ruby-1.9.2-p290 [ x86_64 ]
* ruby-1.9.2-p318 [ x86_64 ]
ruby-1.9.2-p320 [ x86_64 ]
# Put your answers here!
Michael-Riess-Computer:~ michaelriess$ rvm list
rvm rubies
ruby-1.8.7-p302 [ i686 ]
ruby-1.9.2-p290 [ x86_64 ]
=* ruby-1.9.2-p318 [ x86_64 ]
ruby-1.9.2-p320 [ x86_64 ]