Skip to content

Instantly share code, notes, and snippets.

ingemar ingemar

Block or report user

Report or block ingemar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ingemar / params_for.rb
Created Sep 1, 2013
A DRY way to deal with strong parameters in Ruby on Rails 4 together with the excellent gem decent_exposure
View params_for.rb
module ParamsFor
def params_for(model, *attributes)
return if method_defined? "#{model}_params"
define_method "#{model}_params" do
params.require(model).permit attributes
View rspec.rake
# in lib/tasks/rspec.rake
# within namespace
namespace :spec do
desc "Run all specs with RCov"'rcov') do |t|
t.pattern = "./spec/**/*_spec.rb"
t.rcov = true
t.rcov_opts = ['-Ispec --exclude', 'rubygems/*,rcov,.gem/*,blueprints.rb,features/*']
ingemar / gist:649270
Created Oct 27, 2010
How to structure a ruby class
View gist:649270
require 'open-magazine' # requirements
class Article
include Any::Aweseome::Module # includes and extensions
belongs_to :author # relations to other models
attr_accessor :title, :pages # attribute definitions
RESERVED_TITLES = ['Coding Ruby'] # constants...
View cucumber_rows_to_attributes
#table must be a two columned cucumber table
keys = { |key| key.parameterize("_") }
attributes =
attributes = Hash[*attributes]
View Copy stuff from IRB to OS X clipboard
# stick it in your ~/.pryrc
# use 'xsel' or 'xclip' if you're in a Linux environment
def _cp(obj = Readline::HISTORY.entries[-2], *options)
if obj.respond_to?(:join) && !options.include?(:a)
if options.include?(:s)
obj = { |element| ":#{element.to_s}" }
out = obj.join(", ")
elsif obj.respond_to?(:inspect)
View rails_model_with_custom_log_example.rb
class Article < ActiveRecord::Base
LOGFILE = File.join(RAILS_ROOT, '/log/', "article_#{RAILS_ENV}.log")
def validate
log "was validated!"
def log(*args)
args.size == 1 ? (message = args; severity = :info) : (severity, message = args)
You can’t perform that action at this time.