如何在Rails控制台中使用Trailblazer单元?
概念帮助器无法正常工作
irb(main):002:0> c = concept(Resource::Cell, l)
NoMethodError: undefined method `concept' for main:Object
Did you mean? concern
context
from (irb):2
答案 0 :(得分:1)
概念()& cell()是Controller助手,这意味着如果未加载控制器,它们将无法在控制台中运行。但你不需要它们!
使用单元格最简单的方法就是调用它们。你可以使用任何其他红宝石对象。
<强>细胞强>
# concepts/song/cell/cell.rb
module Song::Cell
class Index < Trailblazer::Cell
def show
render
end
end
class Show < Trailblazer::Cell
def show
render
end
end
end
查看强>
%h1
Song#show
%p
Find me in app/concepts/song/view/show.haml
<强>控制台强>
# Any of the following calls - they are all equivalent pretty much
# The spit html output of the cell
Song::Cell::Show.(Song.last).()
Song::Cell::Show.(Song.last).render
Song::Cell::Show.(Song.last).(:show)