大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – 如何在Rails 3中的控件之外渲染模板?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的方法:
@H_197_4@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错误:
@H_197_4@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基本上你需要这样做:
@H_197_4@class HelloWorldController < AbstractController::Base include AbstractController::rendering include AbstractController::Layouts include AbstractController::Helpers include AbstractController::Translation include AbstractController::AssetPaths include ActionController::UrlWriter self.view_paths = "app/views" def show; end end接着:
@H_197_4@HelloWorldController.new.show将返回渲染到String的视图.
以上是大佬教程为你收集整理的ruby-on-rails – 如何在Rails 3中的控件之外渲染模板?全部内容,希望文章能够帮你解决ruby-on-rails – 如何在Rails 3中的控件之外渲染模板?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。