Skip to content

Instantly share code, notes, and snippets.

View derekrockwell's full-sized avatar

Derek Rockwell derekrockwell

  • Zipnosis, Inc.
  • Minneapolis
View GitHub Profile

Keybase proof

I hereby claim:

  • I am derekrockwell on github.
  • I am derekrockwell (https://keybase.io/derekrockwell) on keybase.
  • I have a public key ASDsJ7SwLK461I1nwwX1qb-KCXtqhzitJEUxEZksyoTVYAo

To claim this, I am signing this object:

@derekrockwell
derekrockwell / example.rb
Last active December 20, 2015 18:59
has and belongs to many magic
class User < ActiveRecord::Base
#magically looks up repertoires with user_id = this user's id
has_many :repertoires
end
class Repertoire < ActiveRecord::Base
#songly data and methods
#requires user_id integer on repertoire table
belongs_to :user
end
@derekrockwell
derekrockwell / prefixroutes.rb
Created June 21, 2013 05:34
remove need for prefixing routes within an engine
module DummyEngine
module ApplicationHelper
def method_missing(method, *args, &block)
if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && engine_name.respond_to?(method)
engine_name.send(method, *args)
else
super
end
end
end
@derekrockwell
derekrockwell / secret_token_template.rb
Created May 20, 2013 04:53
Good way of handling secret tokens within apps (leveraging Heroku config variables or some other server based environment variables) Source: http://daniel.fone.net.nz/blog/2013/05/20/a-better-way-to-manage-the-rails-secret-token/
MyApp::Application.config.secret_token = if Rails.env.development? or Rails.env.test?
('x' * 30) # meets minimum requirement of 30 chars long
else
ENV['SECRET_TOKEN']
end
@derekrockwell
derekrockwell / form_helper.rb
Last active December 14, 2015 12:09
MetaSearch update for ActionPack 4.0 to support. Unsure if this has any functionality effects and it is untested, use with caution.
module MetaSearch
module Helpers
module FormHelper
def apply_form_for_options!(record,object,options)
if object.is_a?(MetaSearch::Builder)
builder = object
options[:url] ||= polymorphic_path(object.base)
elsif object.is_a?(Array) && (builder = object.detect {|o| o.is_a?(MetaSearch::Builder)})
options[:url] ||= polymorphic_path(object.map {|o| o.is_a?(MetaSearch::Builder) ? o.base : o})
else
@derekrockwell
derekrockwell / form.html.erb
Last active December 14, 2015 00:49
simple example of a form without a model backend
<%= form_tag('/sample') do |f| %>
<div class="field">
<%= label_tag :var1 %><br />
<%= text_field_tag :var1 %>
</div>
<div class="field">
<%= label_tag :var2 %><br />
<%= text_field_tag :var2 %>
</div>
<div class="actions">