मैं अपने रेल 3 एप्लिकेशन में नियंत्रक के बाहर एक टेम्पलेट प्रस्तुत नहीं कर सकता। मैंने जो गुगल किया है वह सहायक रहा है, और अंततः मुझे http://www.swombat.com/rails-rendering-templates-outside-of-a-contro पर कुछ उपयोगी जानकारी मिली। हालांकि, यह रेल 3 में टूटा हुआ प्रतीत होता है। क्या किसी के पास कोई विचार है कि मैं इस विधि को कैसे ठीक कर सकता हूं या शायद बेहतर दृष्टिकोण के बारे में जानता हूं?मैं रेल 3 में नियंत्रक के बाहर टेम्पलेट कैसे प्रस्तुत कर सकता हूं?
मेरे विधि:
def render_erb(template_path, params)
view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << view
include ApplicationHelper
end
view.render(:file => "#{template_path}.html.erb", :locals => params)
end
त्रुटि:
ActionView::Template::Error: ActionView::Template::Error
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /Users/mikegerstenblatt/Desktop/bluetrain/lib/test.html.erb:17:in `_lib_test_html_erb__366962844_2173671680_68830'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/template.rb:135:in `send'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/template.rb:135:in `render'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications.rb:54:in `instrument'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/template.rb:127:in `render'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:59:in `_render_template'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `instrument'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0/lib/active_support/notifications.rb:52:in `instrument'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:56:in `_render_template'
from /Library/Ruby/Gems/1.8/gems/actionpack-3.0.0/lib/action_view/render/rendering.rb:26:in `render'
from /Users/mikegerstenblatt/Desktop/bluetrain/app/models/generated_website.rb:45:in `render_erb'
from (irb):2
अपने ब्लॉग पोस्ट को 404 – nocache
यहाँ सही ब्लॉग लिंक है: http://www.amberbit.com/blog/2011/12/27/render-views-and-partials-outside-controllers-in-rails- 3/ –
रेल 4 के लिए, मुझे एक्शन व्यू :: लेआउट्स के लिए एक जोड़ जोड़ना पड़ा: "एक्शन व्यू :: लेआउट्स" शामिल करें। – Dushyanth