[英]rails - get url(like url_for) without raising error if not found
我得到這樣的URL:
url_for(:controller => :controller, :action => :action-name)
如果找不到路由,則會引發錯誤。
如果沒有找到路由,我希望它返回空URL。
有什么解決方案?
謝謝。
只需用助手將其包裝即可。 就像是:
def silent_url_for(options = nil)
begin
url_for(options)
rescue SomeException
''
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.