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
Format Meaning | |
%a The abbreviated weekday name (“Sun’’) | |
%A The full weekday name (“Sunday’’) | |
%b The abbreviated month name (“Jan’’) | |
%B The full month name (“January’’) | |
%c The preferred local date and time representation | |
%d Day of the month (01..31) | |
%H Hour of the day, 24-hour clock (00..23) | |
%I Hour of the day, 12-hour clock (01..12) | |
%j Day of the year (001..366) |
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 Post < ActiveRecord::Base | |
# for SO: http://stackoverflow.com/questions/10481389/friendly-id-with-two-parameters | |
# EXAMPLE ASSUMES YOU ARE USING FRIENDLYID 4.X | |
# AND THAT YOU HAVE A SLUG:STRING COLUMN ON THE MODEL | |
# ... | |
extend FriendlyId | |
friendly_id :generate_custom_slug, :use => :slugged | |
# ... |
OlderNewer