Skip to content

Instantly share code, notes, and snippets.

@tkawa
tkawa / twicli_elsewhither.css
Created January 13, 2011 10:51
twicli用CSS Elsewhitherをベースに、Old Twitterになんとなく似せる感じ
@charset "utf-8";
/* ----- twicli.css ----- */
/*
twicli用CSS Elsewhither(http://else.jimdo.com/others/storage/)をベースに、
Old Twitterになんとなく似せる感じ
*/
* {
margin: 0;

RailsGirls, More! #11 2014.01.12

データ保存用モデルをつくる

短い文字列はstring(省略可)、長い文字列はtext名前:型の形で指定する。

$ rails g model interview url question:text answer:text

他には整数integer、true/falseの型boolean、時間datetimeなどがある。

class ErrorsEngine < Rails::Engine
routes.draw do
Site.all.each do |site|
match '(errors)/:status', via: [:get, :post, :put, :patch, :delete], to: 'errors#show', constraints: { host: site.hostname, status: /\d{3}/ }
end
end
end
unless Rails.application.config.consider_all_requests_local
Rails.application.config.exceptions_app = ErrorsEngine.routes
@tkawa
tkawa / concern_patch.rb
Last active December 21, 2015 10:29
included do |mod| ... end としてincludeされたモジュールの情報を使いたい。
module ActiveSupport
module Concern
def append_features(base)
if base.instance_variable_defined?("@_dependencies")
base.instance_variable_get("@_dependencies") << self
return false
else
return false if base < self
@_dependencies.each { |dep| base.send(:include, dep) }
super
@tkawa
tkawa / filter_params.rb
Created July 11, 2013 07:57
https://gist.github.com/tkawa/4745785 の件、FormBuilder(form_forみたいなやつ)がいらなければ、gemなくてもこんなふうに書けばすむというメモ。
class FilterParams < ActionController::Parameters
include ActiveModel::Model
validates :date, format: /\A\d{4}-\d{2}-\d{2}\Z/
validates :q, length: { maximum: 20 }
def initialize(params = {})
params.reverse_merge!(per: '10')
super(params)
end
@tkawa
tkawa / Gemfile
Last active December 19, 2015 03:39 — forked from mislav/example.rb
Fetch full Atom feed from Google Reader
source 'https://rubygems.org'
gem 'curb'
gem 'nokogiri'
gem 'addressable'
# config/routes.rb
# question and answers that the user has
# /users/:user_id/questions
# /users/:user_id/answers
resources :users do
resources :questions
resources :answers
end
@tkawa
tkawa / user.rb
Last active December 16, 2015 17:40
class User < ActiveRecord::Base
def postal_code1
postal_code.split('-', 2).first || ''
end
def postal_code2
postal_code.split('-', 2).second || ''
end
def postal_code1=(value)
splitted = postal_code.split('-', 2)
splitted[0] = value
@tkawa
tkawa / index.html.haml
Last active December 12, 2015 08:39
http://example.com/posts?date=2013-01-01&q=search_word&page=2&per=20 のように、クエリパラメータでフィルタするような場合に、 strong parameters と併用して、 filter_params に default とか validate とか書けるgemを作成中ですがどうでしょう? https://github.com/tkawa/collection_filter/tree/auto-params
-# クエリパラメータもform_forと同じように書ける
= filter_form do |f|
= f.label :date
= f.text_field :date
= f.label :q
= f.search_field :q
= f.button
@tkawa
tkawa / restful-towa-11.md
Last active November 10, 2015 10:06
RESTful#とは勉強会11

RESTful#とは勉強会11 2015.11.10

質問はTwitterへ #RESTudy をつけてどうぞ。

「Webを支える技術」第10章 HTML

重要な用語・概念

注意点