This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxSetup({ | |
data: { authenticity_token: AUTHENTICITY_TOKEN }, | |
beforeSend: function(xhr) { | |
xhr.setRequestHeader("Accept", "text/javascript") | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Page < ActiveRecord::Base | |
acts_as_tree | |
def self.tree | |
hash = find(:all).inject({}) { |hash, p| hash[p.id] = [p, []]; hash } | |
hash.inject([]) { |result, (key, value)| | |
if parent_id = value.first.parent_id | |
hash[parent_id].last << value | |
else | |
result << value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@recipe = Recipe.new(params[:recipe]) | |
if @recipe.save | |
flash[:notice] = 'Recipe was successfully created.' | |
redirect_to recipes_path | |
else | |
flash[:error] = 'The recipe failed to save.' | |
render :action => 'new' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RecipesController < ApplicationController | |
... | |
def new | |
@recipe = Recipe.new | |
end | |
def create | |
@recipe = Recipe.new(params[:recipe]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RecipesController < ApplicationController | |
... | |
def new | |
@recipe = flash[:recipe] || Recipe.new | |
end | |
def create | |
@recipe = Recipe.new(params[:recipe]) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% disabled do %> | |
Everything within this block will not get executed or output. | |
<% raise 'Foobar' # Even Ruby code won't be run %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def disabled | |
# no-op | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rack | |
class GoogleAnalytics | |
TRACKING_CODE = <<-EOCODE | |
<script type="text/javascript"> | |
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); | |
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); | |
</script> | |
<script type="text/javascript"> | |
try { | |
var pageTracker = _gat._getTracker("{{ID}}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Locale | |
def initialize(identifier) | |
@identifier = identifier.to_s | |
end | |
def to_mongo | |
@identifier | |
end | |
def self.from_mongo(mongo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_extensions(filename) | |
extensions, *name = filename.split(".").reverse.slice_before { |f| f[" "] }.to_a | |
[name.flatten.reverse.join("."), extensions.reverse] | |
end | |
describe "#extract_extensions" do | |
specify { extract_extensions("some file name.with dots.html.markdown").should == ["some file name.with dots", ["html", "markdown"]]} | |
specify { extract_extensions("some file name with.dots.html.markdown").should == ["some file name with", ["dots", "html", "markdown"]]} | |
specify { extract_extensions("a b.c d.e").should == ["a b.c d", ["e"]] } | |
specify { extract_extensions("a.b c.a").should == ["a.b c", ["a"]] } |
OlderNewer