Skip to content

Instantly share code, notes, and snippets.

@hassox
hassox / application_controller.ex
Created October 22, 2014 00:53
A first attempt at a usable user controller setup in Phoenix
defmodule CloseBy.ApplicationController do
defmacro __using__(_opts) do
quote do
use Phoenix.Controller
import CloseBy.ApplicationController
alias CloseBy.Router
end
end
end
@hassox
hassox / debug
Last active August 29, 2015 14:08
struct(User, params) does not transfer values
09:52:35.045 request_id=oOTTwz6ywSK5RsianPnN [info] POST /users
RAW PARAMS
09:52:35.069 request_id=oOTTwz6ywSK5RsianPnN [debug] Processing by CloseBy.UserController.create
Accept: text/html
Parameters: %{"user" => %{"confirm_password" => "p", "email" => "foo@foobarbaz.com", "password" => "p"}}
%{"user" => %{"confirm_password" => "p", "email" => "foo@foobarbaz.com",
"password" => "p"}}
THE CREATE PARAMS params["user"]
%{"confirm_password" => "p", "email" => "foo@foobarbaz.com", "password" => "p"}
09:52:35.192 request_id=oOTTwz6ywSK5RsianPnN [info] Sent 422 in 147ms
$ ruby stacked_blocks.rb
START ARRAY THINGS
START ONE
START TWO
START THREE
START FOUR
IN THE MIDDLE OF ARRAYS DOING IT
FINISH FOUR
FINISH THREE
FINISH TWO
class MyController < Application
cache :show, :index
after nil, :only => :create do
eager_cache :show{ |c| c.params[:id] => @article.id}
eager_cache :index
end
def index
@hassox
hassox / gist:6489
Created August 21, 2008 02:37 — forked from bryansray/gist:6482
# My spec ...
it "should not put the value of the last <option> attributes in to the attributes of the select tag" do
content = select(:collection => %w(one two three), :selected => 'three')
content.should_not match_tag(:select, :value => "three", :selected => "selected")
end
def options(col, text_meth, value_meth, attrs, sel, b)
opt_attrs = attrs.dup
options = [b] + col.map do |item|
value = item.send(value_meth)
@hassox
hassox / roles.rb
Created August 23, 2008 13:37 — forked from anonymous/roles.rb
class MerbPrivilege::Roles < MerbPrivilege::Application
def index
@roles = Role.all
@role ||= Role.new
render
end
def create
@role = Role.new(:id => nil, :description => params[:role][:description])
We couldn’t find that file to show.
@hassox
hassox / gist:12186
Created September 23, 2008 00:18 — forked from lukesutton/gist:12185
Merb.logger.info("Compiling routes...")
Merb::Router.prepare do
# Administration
match('/admin').to(:namespace => "admin") do
resources :locations
resources :users
resources :links
match("/offer").to(:controller => "offer") do
match(:method => "get").to(:action => "show").name(:offer)
match("/edit", :method => "get").to(:action => "edit").name(:edit_offer)
@hassox
hassox / gist:12189
Created September 23, 2008 00:27 — forked from lukesutton/gist:12185
Merb.logger.info("Compiling routes...")
Merb::Router.prepare do
# Administration
match('/admin').to(:namespace => "admin") do
resources :locations
resources :users
resources :links
match("/offer").to(:controller => "offer") do
match(:method => "get").to(:action => "show").name(:offer)
match("/edit", :method => "get").to(:action => "edit").name(:edit_offer)
@hassox
hassox / README
Created September 25, 2008 04:57 — forked from anonymous/README
Throw your "static" views in app/views/static... and it just works, page cached and all.