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
2.1.4 :004 > MyClass.ancestors | |
[ | |
[0] MyClass < Object, | |
[1] Object < BasicObject, | |
[2] PP::ObjectMixin, | |
[3] ERB::Util, | |
[4] ActiveSupport::Dependencies::Loadable, | |
[5] JSON::Ext::Generator::GeneratorMethods::Object, | |
[6] Kernel, | |
[7] BasicObject |
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 simple_nested_set(clazz) # Post for example | |
stack = [] # Post for example | |
result = [] | |
clazz.all(:order => "lft").each do |node| | |
if stack.empty? | |
stack.push({:node => node, :children => []}) | |
result << stack.last | |
next | |
end | |
if stack.last[:node].lft < node.lft && node.lft < stack.last[:node].rgt |
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
# Standard Init Script for New Custom Rails 3.1.3 app | |
RailsVersion = "3.1.3" | |
instructions =<<-END | |
Running Standard Init Script for Rails 3.1.3 | |
-------------------------------------------------- | |
During installation a number of questions will arise and |
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
#config/initializers/page_constraint.rb | |
class PageConstraint | |
def initialize | |
@page_paths = Page.all.map { |p| "/#{p.friendly_id}"} | |
end | |
def matches?(request) | |
@page_paths.include?(request.path) | |
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
require "bundler/capistrano" | |
require 'capistrano/ext/multistage' | |
require 'new_relic/recipes' | |
set :application, "sampleapp" | |
set :branch, "master" | |
# deploy from local | |
set :scm, :git | |
set :repository, ".git" | |
set :deploy_via, :copy |
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
# loaded into config/initializers/slug_table_access.rb | |
### HACK TO LOAD SLUG TABLE ACCESS | |
# required for use with path constraints in routes | |
autoload :Slug, 'friendly_id/slug' | |
# Access Slug table via FriendlyId::Slug | |
# NOTE: In FriendlyId 3.x the Slug model is available within your app | |
# This is a hack for FriendlyId 4.x |
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
# app/models/page.rb | |
class Page < ActiveRecord::Base | |
extend FriendlyId | |
friendly_id :title, :use => [:slugged, :history] | |
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
# Renders an ItemContainer as a <ul> element and its containing items as <li> elements. | |
# Prepared to use inside the topbar of Twitter Bootstrap http://twitter.github.com/bootstrap/#navigation | |
# | |
# Register the renderer and use following code in your view: | |
# render_navigation(level: 1..2, renderer: :bootstrap_topbar_list, expand_all: true) | |
class BootstrapTopbarList < SimpleNavigation::Renderer::Base | |
def render(item_container) | |
if options[:is_subnavigation] | |
ul_class = "dropdown-menu" |
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 edit | |
@profile = Profile.find(params[:username]) | |
what = params[:what] | |
if not what.nil? | |
if ["basics", "location", "details", "photos", "interests"].member?(what) | |
render :action => "edit_#{what}" | |
else | |
render :action => "edit_basics" | |
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
config.model PagePart do | |
configure :content do | |
ckeditor true | |
end | |
end |
OlderNewer