为了能够查看用户是否在 Facebook 上分享了我的页面,我希望能够创建这种 URL:
http://graph.facebook.com/?id=http://stylehatch.co/some_unique_user_token
http://stylehatch.co需要作为我的基本 URL。我正在考虑在 User 模型中使用一个方法来构建并返回该 URL,但我无法从我的模型中访问 root_url。
如何从模型中获取应用程序的基本 URL?
假设我的网址看起来像这样:
http://myapp.com/users/new
http://myapp.com/users/2/show
如何从我的模型中获取“ http://myapp.com ”?我已经添加了:
include Rails.application.routes.url_helpers
在我的模型中,但似乎 root_url 为零。有什么想法吗?这是一个模型方法是否正确,或者我应该把它放在一个助手中?
谢谢