This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{#each list:num}} | |
# num:indexが付けられます。 | |
%div {{num}} | |
# JSONデータのリストである場合、name属性の値を拾えます。 | |
%div {{name}} | |
{{/each}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ractive = new Ractive( | |
el: "#hogehoge" | |
template: "#hogehogehoge" | |
data: | |
list: [{name: 'abe chan'}, {name: 'tabe chan'}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hogeがnullのレコードが下になってソートされます。 | |
scope :sorted_hoge_with_null, -> { where(status: :none).order('hoge IS NULL, hoge ASC') } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]+'"'); | |
} |