This file contains hidden or 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 hidden or 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 hidden or 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
| function slugify(str) { | |
| return str.toLowerCase(). | |
| replace(/&/g, 'and'). | |
| replace(/[^a-z0-9']+/g, '-'). | |
| replace(/^-|-$/g, ''); | |
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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) |
OlderNewer