Skip to content

Instantly share code, notes, and snippets.

@matenia
matenia / post.rb
Created May 10, 2012 01:29
Use custom method for FriendlyId (Example)
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
# ...
@matenia
matenia / DateTime.txt
Created March 3, 2012 11:52
strftime options rails:
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)
@matenia
matenia / gist:4247582
Created December 10, 2012 00:00
two forms on one page (slim, not haml)
div class="span12"
table class="table table-hover"
- @list.products.each_with_index do |product, index|
- if !product.id.nil?
tr
td class="span1"
= #TOP FORM
= form_tag(votes_vote_up_path)
= submit_tag "UP"
- if current_user
@matenia
matenia / application_controller.rb
Created November 25, 2012 11:35
Attempt at extracting subdomain mapping to a simple class for use with a whitelabel solution
require 'subdomain_mapper'
class ApplicationController < ActionController::Base
before_filter :check_whitelabel
def check_whitelabel
sd = SubdomainMapper.new(request.subdomain)
prepend_view_path(sd.whitelabel_view_path)
end
end
@matenia
matenia / gist:4021365
Created November 6, 2012 00:14
Failing helper spec calling route helper
### console output
### 1.9.3p172 :018 > app.root_path
### => "/"
# spec/helpers/applcation_helper.rb
require 'spec_helper'
require 'uri'
describe ApplicationHelper do
@matenia
matenia / gist:4021169
Created November 5, 2012 23:42
Failing helper spec calling route helper
# app/helpers/application_helper.rb
module ApplicationHelper
def go_to_page(resource)
polymorphic_path([resource.company, resource])
end
end
# spec/helpers/application_helper_spec.rb
@matenia
matenia / irb_test
Created June 11, 2012 13:19
Stack Overflow #10977092
1.8.7 :012 > a = Post.first
Post Load (0.8ms) SELECT "posts".* FROM "posts" LIMIT 1
=> #<Post id: 88, title: "Random Title", created_at: "2012-06-11 06:13:02", updated_at: "2012-06-11 06:47:57">
1.8.7 :013 > a.changed?
=> false
1.8.7 :014 > a.title = 'moo'
=> "moo"
1.8.7 :015 > a.changed?
=> true
1.8.7 :016 > Post.first.title = 'moo'
@matenia
matenia / gist:2758056
Created May 20, 2012 13:08 — forked from jdkealy/gist:1323514
rails_admin ckeditor implementation
config.model PagePart do
configure :content do
ckeditor true
end
end
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
@matenia
matenia / bootstrap_topbar_list.rb
Created March 2, 2012 14:49 — forked from tmaier/bootstrap_topbar_list.rb
BootstrapTopbarList for simple-navigation and Twitter Bootstrap integration
# 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"