- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
现在我正在使用它,它适用于开发主机,但当我转向生产时,我必须手动更改 {:host => ""} 代码。
def share_all
url = Rails.application.routes.url_helpers.post_url(self, :host => 'localhost:3000')
if user.authentications.where(:provider => 'twitter').any?
user.twitter_share(url)
end
end
我想使用它,然后定义每个环境的default_url_options:
def share_all
url = Rails.application.routes.url_helpers.post_url(self)
if user.authentications.where(:provider => 'twitter').any?
user.twitter_share(url)
end
end
我尝试将其添加到我的 config/environments/development.rb 中,但仍然收到“缺少要链接的主机!请提供 :host 参数或设置 default_url_options[:host]”错误
config.action_controller.default_url_options = {:host => "localhost:3000"}
我什至尝试过这种方式:
config.action_controller.default_url_options = {:host => "localhost", :port => "3000"}
编辑:
我现在也遵循了这个,但仍然是相同的错误指南 http://edgeguides.rubyonrails.org/action_controller_overview.html#default_url_options
class ApplicationController < ActionController::Base
protect_from_forgery
include ApplicationHelper
def default_url_options
if Rails.env.production?
{ :host => "example.com"}
else
{:host => "example1.com"}
end
end
end
这让我发疯,我在这里错过了什么???
最佳答案
好吧,我发现正确的写法是
Rails.application.routes.default_url_options[:host] = 'localhost:3000'
:)
关于ruby-on-rails - 如何设置 config.action_controller.default_url_options = { :host = '#' '} on per environment basis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5691727/
我有一个在我的基本应用程序 Controller 中使用 protect_from_forgery 的 rails3 应用程序。我正在使用 ActionDispatch::IntegrationTes
我正在尝试使用: https://github.com/polleverywhere/asset_fingerprinter 要安装 Rails 3,您需要设置: config.action_cont
在我的 production.rb 中,我将 asset_host 设置为 CloudFront,如下所示: config.action_controller.asset_host = 'http:/
在我的环境文件中,设置: config.action_controller.perform_caching = true 导致 javascript 根本无法加载。 我使用的唯一 javascript
基本上我想加载这个: require "active_record/railtie" require "active_resource/railtie" require "action_mailer/
我已经使用 Cloudfront 为我的 Rails 3 应用设置了 CDN。我创建了 4 个 CNAME 重定向(cdn1.mywebsite.com、cdn2.mywebasite.com 等),
现在我正在使用它,它适用于开发主机,但当我转向生产时,我必须手动更改 {:host => ""} 代码。 post.rb def share_all url = Rails.applicatio
我最近正在进行 Rails 5 升级,当我尝试启动 Rails 控制台时遇到了这个错误: /actionpack-5.0.0/lib/action_controller/test_case.rb:49
我是一名优秀的程序员,十分优秀!