短い文字列はstring
(省略可)、長い文字列はtext
を名前:型
の形で指定する。
$ rails g model interview url question:text answer:text
他には整数integer
、true/falseの型boolean
、時間datetime
などがある。
@charset "utf-8"; | |
/* ----- twicli.css ----- */ | |
/* | |
twicli用CSS Elsewhither(http://else.jimdo.com/others/storage/)をベースに、 | |
Old Twitterになんとなく似せる感じ | |
*/ | |
* { | |
margin: 0; |
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 |
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 |
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 |
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 |
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 |
-# クエリパラメータもform_forと同じように書ける | |
= filter_form do |f| | |
= f.label :date | |
= f.text_field :date | |
= f.label :q | |
= f.search_field :q | |
= f.button |
質問はTwitterへ #RESTudy をつけてどうぞ。