Skip to content

Instantly share code, notes, and snippets.

RailsGirls Tokyo, More! #15 2014.08.16

よちよち.rbで作成しているアプリ(の主にGit操作)と、Railsチュートリアルを進めました。

よちよち.rb Kajaeru Railsアプリ

プルリクエストによる開発の進め方 プルリクエストでレビューを受け、指摘があったときは同一のブランチ上でそれを修正・コミットし、pushする。

1つのプルリクエスト(ブランチ)にはコミットが複数。

RailsGirls, More! #14 2014.07.06

Rails Girls ガイド を最初から進めていきました。

環境設定

Mac OS X 10.9.2

ステップ 3-Bに従って、rbenvを使ってRuby 2.1.2をインストール。

# jQuery optgroupDoubleSelect plugin
# Rewrite of jDoubleSelect
# Copyright (c) Giovanni Casassa & Toru Kawamura
#
# Dual licensed under the MIT (MIT-LICENSE.txt)
# and GPL (GPL-LICENSE.txt) licenses.
#
# http://www.senamion.com/blog/jDoubleSelect.html
jQuery ($) ->
@tkawa
tkawa / application_helper.rb
Created March 26, 2014 11:12
Railsのビューヘルパー内でHamlを使う
module ApplicationHelper
def render_thumbsup_button(options)
options[:url] ||= thumbsup_path
options[:method] ||= :put
options[:count] ||= 0
# ローカル変数を渡したいときのみ locals が必要
render inline: <<-HAML.strip_heredoc, type: :haml, locals: options
.thumbsup
= form_tag url, method: method do
%button.btn.btn-xs
/*
This widget shows Recent Posts on your Tumblr blog.
Its dependency is jQuery.
Usage:
1) Add html:
<div id="recent-posts"></div>
2) Download this script and upload it on your server.

RailsGirls, More! #12 2014.03.01

たのしいRuby 第12章 Numeric p240 練習問題

(1) 摂氏温度を華氏温度に変換するメソッド
f = c * 9 / 5 + 32

(2) 華氏を摂氏に変換するメソッド
移項して変換式を求める。→移項とは両辺に同じ数を足す・引く・掛ける・割る

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