validates_presence_of :match,
:message => "for your name and password could not be found. Did you #{link_to "forget your password", help_person_path}?"
这就是我想要做的。我可以插入在模型中设置的变量,但使用像“link_to”这样的简单Rails代码似乎不起作用。这是一个无赖。
答案 0 :(得分:2)
您不能也不应该从模型中调用link_to
方法。但是,您可以访问命名路由,如下所示:
class PostHack
include Rails.application.routes.url_helpers
end
class Post < ActiveRecord::Base
validates_presence_of :match,
:message => "<a href='#{PostHack.new.send :admin_posts_path}'>My link</a>"
end
非常hackish。我希望你不要用它。