View CoffeeScript
window.bootstrapAlert = (type, message) -> | |
$('#alert_message').text message | |
$('#alert').addClass "alert-#{type}" | |
$("#alert").slideDown() | |
setTimeout (-> | |
$("#alert").slideUp(400, -> | |
$('#alert').removeClass "alert-#{type}" | |
) | |
), 5000 |
View api_provider_host.rb
class ApiProviderHost | |
ENVIRONMENTS = [:development, :test, :staging, :production] | |
ALIASES = { | |
dev: :development, testing: :test, stage: :staging, show: :staging, | |
live: :production, prod: :production | |
} | |
FALLBACKS = { | |
development: [:development, :test, :staging, :production], | |
test: [:test, :development, :staging, :production], | |
staging: [:staging, :production], |
View _javascript_response.js.erb
<% message = flash[:notice] || flash[:alert] %> | |
<% flash.delete(:notice); flash.delete(:alert) %> | |
<% alert = message.present? ? "alert('#{message}');" : '' %> | |
<% if <a href="/path">@path</a>.present? %> | |
$.ajax({ url: "<%= @path %>", data: <%= raw @data.to_json %>, type: "<%= @method.to_s.upcase %>", dataType: "script"}).done(function(data) { | |
eval(data); | |
<%= raw alert %> | |
}) | |
.fail(function(data) { |
View example.html.erb_spec.rb
describe 'example.html.erb' do | |
it 'renders HTML like this' do | |
render | |
compare_texts rendered, 'example.html' | |
end | |
end |
View example.rb
class MusicArtist < ActiveRecord::Base | |
include LastfmRequest | |
end | |
lastfm = Lastfm.new(LastfmApiKey, LastfmApiSecret) | |
# Simplest option | |
lastfm_artist = artist.lastfm_request(lastfm, :artist, :get_info, 'The artist you supplied could not be found', artist: 'Dummy') | |
# Option raise_if_response_is_just_nil |
View railscasts_episodes.rb
require 'rubygems' | |
require 'octokit' # gem install octokit | |
page = 1 | |
catch(:done) do | |
while (repositories = Octokit.repositories('railscasts', page: page, per_page: 100, sort: 'created', direction: 'desc')).length > 0 | |
repositories.each do |repository| | |
throw :done if File.exist? repository.name | |
View app-presenters-presenter.rb
class Presenter | |
def initialize(subject, options = {}) | |
@subject = subject | |
init_haml_helpers | |
end | |
private | |
def method_missing(*args, &block) | |
@subject.send(*args, &block) |