我有一个演示者,我想让each_with_index方法可用。我在我的基本演示者中添加了include Enumerable
但是,我仍然得到一个no方法错误。我目前的代码如下:
<% @bids.each_with_index do |bid, index| %>
<% present bid do |bid_presenter| %>
<div class="large-4 medium-4 columns <%= bid_presenter.last_column %>"></div>
<% end %>
<% end %>
class BidPresenter < BasePresenter
presents :bid
def last_column
if index == bid.size - 1
'end'
end
end
end
class BasePresenter
include Enumerable
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
# if h is missing fallback to template
def method_missing(*args, &block)
@template.send(*args, &block)
end
end
# GET /bids
# GET /bids.json
def index
@bids = current_user.bids
end
答案 0 :(得分:0)
您要将所有未明确实施的方法转发给@template
。无论@template
是什么,似乎都没有正确实施each
。您需要@template
正确回复each
。