Skip to content

Instantly share code, notes, and snippets.

View nyaahara's full-sized avatar

nyaahara nyaahara

  • Beer And Tech
  • Tokyo
View GitHub Profile
@nyaahara
nyaahara / gist:096840291a54c1ea6a71
Created December 14, 2014 09:21
Ractive.jsでループする(haml)
{{#each list:num}}
# num:indexが付けられます。
%div {{num}}
# JSONデータのリストである場合、name属性の値を拾えます。
%div {{name}}
{{/each}}
@nyaahara
nyaahara / gist:52651d972de4ae7e53f4
Created December 14, 2014 09:18
Ractive.jsでループする(coffee script)
ractive = new Ractive(
el: "#hogehoge"
template: "#hogehogehoge"
data:
list: [{name: 'abe chan'}, {name: 'tabe chan'}]
@nyaahara
nyaahara / gist:bf2084ec2e7b5432d0fa
Last active August 29, 2015 14:11
orderするとwhereで絞り込んだレコードが復活しちゃう
class Hoge < ActiveRecord::Base
has_many :fugas
end
class Fuga < ActiveRecord::Base
belongs_to :hoge
end
# statusがnullのレコードだけが取得
Hoge.all.includes(:fugas).references(:fugas).where('fugas.status is null').first.fugas
@nyaahara
nyaahara / gist:2d2e4111fbe87b5d587b
Created December 11, 2014 16:57
scopeでwhereしてorder(nullを含める)
# hogeがnullのレコードが下になってソートされます。
scope :sorted_hoge_with_null, -> { where(status: :none).order('hoge IS NULL, hoge ASC') }
@nyaahara
nyaahara / Model
Created December 10, 2014 12:25
ActiveRecord:scopeをmergeする(引数も取れるよ!)
class Parent << ActiveRecord::Base
has_many :childs
end
class Child << ActiveRecord::Base
belong_to :parent
scope :hoge_is_true, ->(args){ where(hoge: :true).where(hage: :args) }
end
Parent.includes(:childs).references(:childs).merge(Child.hoge_is_true(1))
var initial_values = link.attributes['initial_values']; // Initial value ( format JSON )
// Add initial value.
initial_values = (initial_values)?JSON.parse('{'+initial_values.value+'}'):'';
for(var key in initial_values){
var pattern = '['+key+']"';
content = content.replace(pattern, pattern+' value="'+initial_values[key]+'"');
}