如何在model中使用url_helpers

如果想在model中使用类似 url_path 这样的helper方法, 可以这样:

class User < ActiveRecord::Base

  include Rails.application.routes.url_helpers
  .....
  def base_url
     user_path(self)
  end
  
  end
comments powered by Disqus