Rails link_to include protocol and www depending on environment

时间:2017-08-03 07:11:38

标签: ruby-on-rails ruby

Is there a good way to have link_to use the full url, including the protocol ( https over http ) and www but only on in production environment? Development and Staging can stay the same.

2 个答案:

答案 0 :(得分:1)

我想你目前正在使用这种代码:link_to my_ressource_path()

你应该做什么:

  • 完整网址link_to my_ressource_url()
  • https :添加以下内容,更改 config / environments / production.rb 文件:
routes.default_url_options = { host: 'YOU_WEBSITE_URL', protocol: 'https'  }

答案 1 :(得分:0)

使用*_url路由助手与*_path助手link_to

例如,您可能正在使用link_to users_path,然后只需使用link_to users_url