2011-09-13 15 views
6

मैं एक रेल परियोजना को अद्यतन कर रहा हूं और कोड का एक टुकड़ा पाया जो रेल 3 और रूबी 1.9.2 में काम नहीं करता है (यह रेल 2.3 और रूबी 1.8.7 में किया गया है) और वैसे भी काफी गन्दा दिखता है!इस काम को रेल 3 में कैसे बनाया जाए?

def speech_box(title, options = {}, &block) 
    block_to_partial 'layouts/speech_box', options.merge(:title => title), &block 
    end 

    def block_to_partial(partial_name, options = {}, &block) 
    options.merge!(:body => capture(&block)) 
    concat(render(:partial => partial_name, :locals => options), block.binding) 
    end 

मैं निम्न त्रुटि हो रही है जब मैं फोन:

<% speech_box("hello") do %> 
    <p>lorem ipsum</p> 
    <% end %> 

तर्कों की गलत संख्या (2 1 के लिए)

यह कैसे आ रेल में काम नहीं करता 3?

actionpack (3.1.0) lib/action_view/helpers/text_helper.rb:51:in `concat' 
app/helpers/application_helper.rb:277:in `block_to_partial' 
app/helpers/application_helper.rb:272:in `speech_box' 
app/views/talks/new.html.erb:46:in `_app_views_talks_new_html_erb__3484685084088947386_2193902320' 
actionpack (3.1.0) lib/action_view/template.rb:144:in `block in render' activesupport (3.1.0) 
lib/active_support/notifications.rb:55:in `instrument' actionpack (3.1.0) 
lib/action_view/template.rb:142:in `render' actionpack (3.1.0) 
lib/action_view/renderer/template_renderer.rb:40:in `block (2 levels) in render_template' actionpack (3.1.0) 
lib/action_view/renderer/abstract_renderer.rb:33:in `block in instrument' activesupport (3.1.0) 
lib/active_support/notifications.rb:53:in `block in instrument' activesupport (3.1.0) 
lib/active_support/notifications/instrumenter.rb:21:in `instrument' activesupport (3.1.0) 
lib/active_support/notifications.rb:53:in `instrument' actionpack (3.1.0) 
lib/action_view/renderer/abstract_renderer.rb:33:in `instrument' actionpack (3.1.0) 
lib/action_view/renderer/template_renderer.rb:39:in `block in render_template' actionpack (3.1.0) 
lib/action_view/renderer/template_renderer.rb:47:in `render_with_layout' actionpack (3.1.0) 
lib/action_view/renderer/template_renderer.rb:38:in `render_template' actionpack (3.1.0) 
lib/action_view/renderer/template_renderer.rb:12:in `block in render' actionpack (3.1.0) 
lib/action_view/renderer/abstract_renderer.rb:22:in `wrap_formats' actionpack (3.1.0) 
lib/action_view/renderer/template_renderer.rb:9:in `render' actionpack (3.1.0) 
lib/action_view/renderer/renderer.rb:36:in `render_template' actionpack (3.1.0) 
lib/action_view/renderer/renderer.rb:17:in `render' actionpack (3.1.0) 
lib/abstract_controller/rendering.rb:120:in `_render_template' actionpack (3.1.0) 
lib/action_controller/metal/streaming.rb:250:in `_render_template' actionpack (3.1.0) 
lib/abstract_controller/rendering.rb:114:in `render_to_body' actionpack (3.1.0) 
lib/action_controller/metal/renderers.rb:30:in `render_to_body' actionpack (3.1.0) 
lib/action_controller/metal/compatibility.rb:43:in `render_to_body' actionpack (3.1.0) 
lib/abstract_controller/rendering.rb:99:in `render' actionpack (3.1.0) 
lib/action_controller/metal/rendering.rb:16:in `render' actionpack (3.1.0) 
lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render' activesupport (3.1.0) 
lib/active_support/core_ext/benchmark.rb:5:in `block in ms' 
............. 
+0

क्या हम एक पूर्ण निशान देख सकते हैं? – cbrauchli

+0

ने इसे अभी जोड़ा है – amaseuk

उत्तर

4

concat चला गया है:

के रूप में नीचे का अनुरोध किया, यहाँ का पता लगाने है। बस concat हटाएं और <% के बजाय <%= का उपयोग करके speech_box पर कॉल करना सुनिश्चित करें।

def block_to_partial(partial_name, options = {}, &block) 
    options.merge!(:body => capture(&block)) 
    render(:partial => partial_name, :locals => options) 
end 

<%= speech_box("hello") do %> 
    <p>lorem ipsum</p> 
<% end %> 
संबंधित मुद्दे