class DataListBuilder
include ActionView::Helpers::TagHelper
include ActionView::Helpers::CaptureHelper
include ActionView::Helpers::UrlHelper
attr_accessor :object, :output_buffer
def initialize(object)
@object, @output_buffer = object, nil
end
def column (&block)
if block_given?
content_tag(:li, block.call(self))
else
content_tag(:li, "")
end
end
def options_column(&link_block)
if block_given?
content_tag(:li, content_tag(:dl, "<dt><a href='#'> </a></dt><dd><ul>#{link_block.call(self)}</ul></dd>".html_safe, :class=>'options'))
else
content_tag(:li, "")
end
end
def link_item(title, url, options={})
content_tag :li, link_to(title, url, options)
end
end
원하는 출력은
하지만 생성 중입니다.
<li><a href="/leads/309">Show</a></li>
<li><a href="/leads/309/edit">Edit</a></li>
<li><a id="309" class="display-newxdoc" href="leads/309/notes/new">New Note</a></li>
<li><a href="/leads/309/opportunities/new">Create Opportunity</a></li>
<li><dl class="options"><dt><a href="#"> </a></dt><dd><ul style="display: none;">
<li><a data-remote="true" class="plus" href="leads/details/309"> </a></li>
<li>3w</li>
<li>Simon Wu</li>
<li>1-714-553-0888</li>
<li>[email protected]</li>
<li>Unified Beat</li>
<li><a href="/leads/309">Show</a></li>
<li><a href="/leads/309/edit">Edit</a></li>
<li><a id="309" class="display-newxdoc" href="leads/309/notes/new">New Note</a></li>
<li><a href="/leads/309/opportunities/new">Create Opportunity</a></li>
</ul></dd></dl></li>
</ul></dd></dl></li>
어느 하나라도 도움이 될 수 있습니까? 그 안에.
전체 코드는 here로 표시됩니다.
정말로 정말로 감사드립니다. 그것은 작동합니다. 그것은 또한 내면과 내부에서 일어나는 일에 대한 완전한 통찰력을주었습니다. 이제 유일한 문제는'lead_path (객체)'와 라우트 메소드가 작동하지 않는다는 것입니다. 그것은'ActionView :: Template :: Error (#에 대한 정의되지 않은 메소드'lead_path ') :'오류를 생성합니다. 이것은 목록에 남아있는 유일한 것입니다. 그것을 해결하는 데 도움주세요. –
@ Nazar Huaain - 링크를 사용하여 문제를 해결하는 답변을 업데이트했습니다. 'Rails.application.routes.url_helpers'를 포함하고'controller'를'DataListBuilder'에 추가했습니다. 보기에'object.id'를 추가했습니다. http://stackoverflow.com/questions/341143/can-rails-routing-helpers-i-e-mymodel-pathmodel-be-used-in-models/5456103#5456103 자세한 정보는 –
고맙습니다. 그게 내 문제를 해결해 줬어. –