Skip to content

Instantly share code, notes, and snippets.

@mnishiguchi
mnishiguchi / Gemfile
Created June 3, 2015 19:03
A sample application using React.js and Fluxxor with Ruby on Rails. The application is based on the Fluxxor's documentation.
source 'https://rubygems.org'
# ruby 2.2.1p85
gem 'rails', '4.2.1'
gem 'pg', '~> 0.17.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '~> 2.7.1'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails', '~> 4.0.3'
gem 'turbolinks', '~> 2.5.3'
gem 'jbuilder', '~> 2.0'
@mnishiguchi
mnishiguchi / file0.txt
Last active January 10, 2016 21:00
Bootstrap3 tabs - コントローラに応じて、activeタブを変更する。 ref: http://qiita.com/mnishiguchi/items/fbcfc1721787395fa6f2
-# デフォルト:#tabs_table_all_itemsがactive.
-# MovingItemsControllerからレンダリングされた場合のみ例外的に#tabs_add_formをactiveにする。
-# クラスのリスト
- tab_active = "active"
- tab_default = ""
- content_default = %w[tab-pane fade]
- content_active = %w[tab-pane fade active in]
-# クラス交換機
@mnishiguchi
mnishiguchi / application_helper.rb
Last active August 29, 2015 14:24
Rails - content_tagでビューヘルパーを自作する。 ref: http://qiita.com/mnishiguchi/items/d7a225e89806666e48fc
module ApplicationHelper
# kv_names: 配列 [key名, value名]
# collection: hash { key1: value1, key2: value2, ... }
def kv_table_for(kv_names, collection={})
thead = content_tag(:thead) do
content_tag(:tr) do
tags = kv_names.map { |column| content_tag(:th, column, class: "text-center") }
safe_join tags
@Records = React.createClass
#...
render: ->
<div>
<table className='table table-bordered'>
<thead>
<tr>
<th>Name</th>
<th>Vol</th>
<th>Qty</th>
@mnishiguchi
mnishiguchi / NewRecordForm.js.coffee
Last active September 15, 2016 08:37
React.js, jQuery-ui, Autocompleteで語句候補ドロップダウン ref: http://qiita.com/mnishiguchi/items/73f9540fe38854df7379
@NewMovingRecordForm = React.createClass
# 元の状態
getInitialState: ->
name: ""
volume: ""
quantity: ""
room: ""
category: ""
description: ""
@mnishiguchi
mnishiguchi / App.js.coffee
Last active September 15, 2016 08:35
React.js + Chart.jsでインタラクティブなグラフを書く ref: http://qiita.com/mnishiguchi/items/226c0a4bd85e4da54f42
R = React.DOM
# Canvases for charts
PieChartCanvas = React.createClass
render: ->
R.canvas
style: { height: 200, width: 200 }
BarChartCanvas = React.createClass
@mnishiguchi
mnishiguchi / CustomChartメソッド使用例
Last active August 29, 2015 14:25
React.js - 使い回し可能なChart.jsラッパークラス ref: http://qiita.com/mnishiguchi/items/aeb6231b405051aba85c
# "Bar"を引数とすると、Bar Chartを作ります。
React.createElement CustomChart("Bar"),
name: "barChart" # 固有の名前
data: @dataForBarChart() # グラフタイプに対応したデータ構造であること
height: 200
width: 400
# "Pie"を引数とすると、Pie Chartを作ります。
React.createElement CustomChart("Pie"),
name: "pieChart"
@mnishiguchi
mnishiguchi / Controller
Last active August 29, 2015 14:25
pg_searchで簡単に検索機能追加 ref: http://qiita.com/mnishiguchi/items/02d96cdc8575d268a937
class IngredientsController < ApplicationController
before_action :search_ingredients, only: :index # indexアクションのみ
def index
end
...
private
@mnishiguchi
mnishiguchi / file0.txt
Last active September 7, 2015 19:32
ActiveModel::Modelで簡単に検索機能追加 ref: http://qiita.com/mnishiguchi/items/4681bb16f440d6032eaf
class SearchForm
include ActiveModel::Model
attr_accessor :q
end