如何在 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
如何在 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
concept() 和 cell() 是控制器助手,这意味着如果未加载控制器,它们将无法在控制台中工作。但你不需要它们!
使用 cell 最简单的方法就是像 . 你会用任何其他红宝石对象。
细胞
# 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)