我已经开始将我的所有视图逻辑移到演示器上,并且在我的索引视图上得到了下面的错误NameError at /bids uninitialized constant Bid::ActiveRecord_Associations_CollectionProxyPresenter。演示者在此模型的所有其他视图中工作,索引除外。我添加了我尝试过的修正代码。
代码:
索引视图:
<% present @bids do |bid_presenter| %>
<% end %>
# tried @bids to match controller
# <% present @bids do |bid_presenter| %>
# <% end %>bid_presenter.rb:
class BidPresenter < BasePresenter
presents :bid
# tried :bids
# presents :bids
endbase_presenter.rb:
class BasePresenter
def initialize(object, template)
@object = object
@template = template
end
private
def self.presents(name)
define_method(name) do
@object
end
end
# h method returns the template object
def h
@template
end
def method_missing(*args, &block)
@template.send(*args, &block)
end
endbids_controller.rb:
def index
@bids = current_user.bids
end发布于 2015-01-09 02:07:52
你试过:
<% @bids.each do |bid| %>
<% present bid do |bid_presenter| %>
<% end %>
<% end %>演示者正在展示模型的一个实例;您的代码试图呈现一个ActiveRecord::集合或其他东西。
https://stackoverflow.com/questions/27852311
复制相似问题