1

シンプルなすべてのものを表示するビューを設定するときに、Trailblazer で問題が発生しました。

手術

class Thing < ApplicationRecord
  class ShowAll < Trailblazer::Operation
    include Model
    model Thing, :all   #why :all is not working here?

    def process
    end
  end
end

コントローラ

class PageController < ApplicationController
  def index
    run Word::ShowAll
  end
end

:allデータベースからすべてのものを:find取得するために機能しないのに、ID を介して 1 つを取得するために機能するのはなぜですか?

4

2 に答える 2

1

Trailblazer::Model#modelあなたがやっているように呼び出すことは、TrailBlazer::Operaration#model!メソッドをオーバーライドするためのショートカットです。したがって、あなたがやりたいと思われることは次のとおりです。

class Thing < ApplicationRecord
  class ShowAll < Trailblazer::Operation
    def model!(params)
      Thing.all # add any filtering or pagination here
    end
  end
end

そして、モデルをセットアップするが操作のメソッドを呼び出さないようにするpresent代わりに、コントローラー呼び出しで。runprocess

class PageController < ApplicationController
  def index
    present Word::ShowAll
  end
end
于 2016-11-19T14:25:31.203 に答える