【发布时间】:2011-04-17 05:41:22
【问题描述】:
现在我正在使用它,它适用于开发主机,但是当我转移到生产环境时,我必须手动更改 {:host => ""} 代码。
post.rb
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:
post.rb
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]”错误
development.rb
config.action_controller.default_url_options = {:host => "localhost:3000"}
我什至这样尝试过:
development.rb
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
这让我发疯了,我在这里错过了什么???
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 actioncontroller