Skip to content

Instantly share code, notes, and snippets.

View tbuehlmann's full-sized avatar

Tobias Bühlmann tbuehlmann

View GitHub Profile
require 'haml'
puts RUBY_ENGINE # "ruby"
puts RUBY_VERSION # "2.1.1"
puts Haml::VERSION # "4.0.5"
def hash1
{:bread => 'white', :filling => 'peanut butter and jelly'}
end
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
add_breadcrumb 'Home', root_url
def breadcrumbs
@breadcrumbs ||= []
end
helper_method :breadcrumbs
def add_breadcrumb(name, url, options = {})
class Ability
include CanCan::Ability
def initialize(user, *args)
super(*args)
alias_action :new, to: :write
alias_action :create, to: :publish
user ||= User.new # guest user (not logged in)
if user.has_role? :admin
can :manage, :all
location ~ ^/(assets)/ {
gzip_static on;
expires 1y;
add_header Cache-Control public;
}
module ApplicationHelper
def content_helper(id)
content_tag(:div, yield, id: id)
end
end
<%= form_for(@user) do |f| %>
<% User::TYPES.each do |type| %>
<%= f.radio_button :user_type, type %>
<% end %>
<%= f.submit %>
<% end %>
<%= form_for(@user) do |f| %>
<% User.types.each_key do |type| %>
<%= f.radio_button :type, type %>
<% end %>
<%= f.submit %>
<% end %>
# app/models/artist.rb
class Artist < User
end
def guest_editor?
desks.where(name: 'Guest Editor').exists?
end
Rails.application.routes.draw do
# 1
resources :notifications, only: [] do
resources :reactions, only: :create
end
# 2
post '/notifications/:notification_id/reactions'
# 3