Skip to content

Instantly share code, notes, and snippets.

nyaahara nyaahara

View GitHub Profile
@nyaahara
nyaahara / gist:096840291a54c1ea6a71
Created Dec 14, 2014
Ractive.jsでループする(haml)
View gist:096840291a54c1ea6a71
{{#each list:num}}
# num:indexが付けられます。
%div {{num}}
# JSONデータのリストである場合、name属性の値を拾えます。
%div {{name}}
{{/each}}
@nyaahara
nyaahara / gist:52651d972de4ae7e53f4
Created Dec 14, 2014
Ractive.jsでループする(coffee script)
View gist:52651d972de4ae7e53f4
ractive = new Ractive(
el: "#hogehoge"
template: "#hogehogehoge"
data:
list: [{name: 'abe chan'}, {name: 'tabe chan'}]
@nyaahara
nyaahara / gist:bf2084ec2e7b5432d0fa
Last active Aug 29, 2015
orderするとwhereで絞り込んだレコードが復活しちゃう
View gist:bf2084ec2e7b5432d0fa
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 Dec 11, 2014
scopeでwhereしてorder(nullを含める)
View gist:2d2e4111fbe87b5d587b
# hogeがnullのレコードが下になってソートされます。
scope :sorted_hoge_with_null, -> { where(status: :none).order('hoge IS NULL, hoge ASC') }
@nyaahara
nyaahara / Model
Created Dec 10, 2014
ActiveRecord:scopeをmergeする(引数も取れるよ!)
View Model
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))
View gist:4ce15bb88482a794fe1f
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]+'"');
}
You can’t perform that action at this time.