emp*_*e29 5 ruby ruby-on-rails partials models
我有一个Rails 2.3.5应用程序,我试图从模型中呈现几个部分(我知道,我知道 - 我不应该).我这样做的原因是我将Comet服务器(APE)集成到我的Rails应用程序中,需要根据Model的事件(例如after_create)推出更新.
我试过这样做:
ActionView::Base.new(Rails::Configuration.new.view_path).render(:partial => "pages/show", :locals => {:page => self})
Run Code Online (Sandbox Code Playgroud)
这允许我渲染不是用户助手的简单部分,但是如果我尝试在我的部分中使用link_to,我会收到一条错误说明:
undefined method `url_for' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
我确保传递给"project_path(project)"的对象不是nil.我也试过包括:
include ActionView::Helpers::UrlHelper
include ActionController::UrlWriter
Run Code Online (Sandbox Code Playgroud)
在包含进行上述"render"调用的方法的Module中.
有谁知道如何解决这个问题?
谢谢
我们使用render_anywhere gem并且对它感到满意.
来自README:
require 'render_anywhere'
class AnyClass
include RenderAnwhere
def build_html
html = render :template => 'normal/template/reference',
:layout => 'application'
html
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1441 次 |
| 最近记录: |