This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'curb' | |
gem 'nokogiri' | |
gem 'addressable' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# クエリパラメータもform_forと同じように書ける | |
= filter_form do |f| | |
= f.label :date | |
= f.text_field :date | |
= f.label :q | |
= f.search_field :q | |
= f.button |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/i18n_exception_handler.rb | |
I18n.exception_handler = ->(exception, locale, key, options) do | |
if exception.is_a?(I18n::MissingTranslation) | |
Rails.logger.warn exception.message if Rails.env.development? | |
key.to_s.split('.').last.humanize | |
else | |
raise exception | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Hatebu Mix Twitter Comment | |
// @namespace http://www.4bit.net/ | |
// @include http://b.hatena.ne.jp/entry/* | |
// @description はてブのコメントリストにTwitterコメントを合成表示 | |
// @author tkawa | |
// @version 1 | |
// ==/UserScript== | |
(function(d, func) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GroupsController < AppController | |
resources_path 'users/groups', 'my/groups' | |
def index | |
end | |
def show | |
end | |
def update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# skip validates (summary) | |
class SomeModel < ParentModel # < ActiveRecord::Base | |
_callback = _validate_callbacks.find {|c| | |
c.raw_filter.is_a?(ActiveModel::Validations::InclusionValidator) && # class name | |
c.raw_filter.instance_variable_get(:@attributes).try(:include?, :attribute_name) } | |
skip_callback(:validate, _callback.kind, _callback.filter) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SubscriptionsController < ApplicationController | |
before_filter :authenticate_user! | |
def show | |
@page_css = 'user' | |
@subscription = current_user.active_subscription | |
@upcoming = current_user.upcoming_subscription | |
@latest = current_user.latest_valid_subscription | |
end |