1

我有一个辅助类,它呈现部分内容以将内容存储在数据库中。

它工作正常,但是当视图包含由 url 助手提供的 url 时

<%= link_to "Show project", projects_url, class: "button" %>

它抛出以下异常

# 未定义的局部变量或方法 projects_url

在名为 NotificationRender 的助手中呈现的代码是

def render(options)
    viewer = ActionView::Base.new()
    viewer.view_paths = ActionController::Base.view_paths
    viewer.extend ApplicationHelper    
    viewer.render options
end

我将此助手包含在类通知中

class Notification < ActiveRecord::Base
  include NotificationRender

  .....
  def self.create_for(user, event, params)   
      template = "notifications/_email_project"
      list_params = {:template => template,:locals => params}
      notification = Notification.new
      notification.message = notification.render(list_params) #here I render the partial
      notification.subject = I18n.t "subject.#{event}"
      notification.to = user.email     
      notification.save
 end

end
4

0 回答 0