从类中呈现部分时,Url帮助程序不可用

时间:2012-12-03 14:37:14

标签: ruby-on-rails

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

它工作正常但是当视图包含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

0 个答案:

没有答案