I use the Rails.application.routes.generate()
and Rails.application.routes.recognize_path()
in my application to disassemble and generate URLs using the Rails routing table. I never had a problem with this using the Rails 2.3.x series but since Rails 3 (specifically 3.1.3) I've been getting the following error when invoking these commands
RuntimeError: route set not finalized
Two questions :
In Rails 3, you don't use this technic. You need include Rails.application.routes.url_helpers
after you can use your named_route
class User < ActiveRecord::Base
include Rails.application.routes.url_helpers
def my_own_url
user_url(self)
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.