我有一个帮助类,它将部分内容存储在数据库中。
它工作正常但是当视图包含url helper提供的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
我将这个助手包含在Notification
类中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