Skip to content

Instantly share code, notes, and snippets.

View rsl's full-sized avatar
🏳️‍🌈
still a bad fish and free bird

Russell Norris rsl

🏳️‍🌈
still a bad fish and free bird
View GitHub Profile
@rsl
rsl / example.rb
Last active August 29, 2015 13:57 — forked from anonymous/gist:9549170
def insert_flash
content_tag :div, class: 'flash' do
flash.each do |name, msg|
add_flash name, msg
end
end
end
private
= form_for Comment.new do |f|
= f.text_area :body
= f.button t("button.submit")
- @video.comments.reverse.each do |comment|
- next unless comment.persisted?
%div{class: 'comment', id: "comment_#{comment.id}"}
= simple_format comment.body
@rsl
rsl / mcreate
Last active August 29, 2015 13:59 — forked from andrewfree/mcreate
def create
# current_user = User.first
if moment_params.empty?
render status: 406, nothing: true and return
else
@moment = current_user.moments.build(moment_params)
if @moment.save
render "moments/show", status: 201
else
render status: 422, nothing: true # We should know about things like this.
@rsl
rsl / bank_proj.rb
Last active August 29, 2015 14:00 — forked from btn0s/bank_proj
# Tip: If you name your gist foo.rb it will highlight the code as Ruby.
class Account
# Two things here. First you never use the reader methods you define here.
# You can either refactor the code to use them [see other gist]
# or just remove them and keep using the instance variables.
# Second, usually Rubyists [we have a name!] group class-level code
# like attr_reader or defining constants apart from the method definitions
# with newlines. Multiple calls of similar types [like another attr_reader here]
# would be back-to-back [no newlines] though. Just a readability thing.
attr_reader :name, :balance
@rsl
rsl / gist:11389367
Last active August 29, 2015 14:00 — forked from btn0s/gist:11389343
class Sleigh
USERS = {
"Santa Claus": "Ho Ho Ho!"
}
def authenticate(name, password)
USERS[name] == password
end
end
get_values(form_elements_cache, question_element).inject(radio_buttons = "") do |radio_buttons, value_hash|
html_options[:id] = "#{id}_#{i += 1}"
html_options[:onclick] = select_answer_event if follow_ups
codes << {:id => html_options[:id], :code => value_hash[:code]}
unless question_element.export_column.blank?
cdc_attributes << {:id => html_options[:id], :export_conversion_value_id => value_hash[:export_conversion_value_id]}
end
selected_code = @object.radio_button_answer.include?(value_hash[:value]) ? value_hash[:code] : "" unless !selected_code.blank?
require 'coffee'
require 'water'
require 'cup'
require 'carsten'
cup = Cup.new(:size => 'small')
cup.add(Coffee::Espresso.new(:shots => 3))
cup.add(Water::Ice.new(:cubes => 12))
cup.join
class PostsController < ApplicationController
# Automatically create the strong parameters required method
def PostsController.filter_parameters(options = {})
options[:for] = [options[:for]] if options[:for].is_a?(Symbol)
options[:for].each do |action_name|
define_method("#{action_name.to_s}_params") do
base = options[:require].keys.first
params.require(base).permit(*options[:require][base])
end
@rsl
rsl / gist:76227
Created March 9, 2009 12:21 — forked from radar/gist:76111
Please confirm the upgrade from
%strong= Plan[session[:old_plan_id]]
to
%strong= Plan[session[:new_plan_id]]
%br
%br
You are upgrading your
%strong Orchestrate
account located at
%string
module ActiveSupport
module CoreExtensions #:nodoc:
module String
module Conversions
def to_klass
self.classify.constantize
rescue NameError
nil
end
end