【问题标题】:How can I run a Controller Action from Rails Console, but setting the request.shot?如何从 Rails 控制台运行控制器操作,但设置 request.shot?
【发布时间】:2013-04-07 15:12:59
【问题描述】:

我正在开发一个多租户应用程序,因此几乎所有内容(从路由开始)都希望有一个看起来像“tenant_id.myapp.com”的“request.host”。

我正在尝试从 Rails 控制台运行控制器操作,但我无法弄清楚这一点。

最简单的方法似乎是“app.get”,但我不知道如何设置主机。

我还看到an answer 提到使用“ActionController::TestProcess”,据我了解,它已从 Rails 中删除(或者如果没有,我还没有找到如何包含它)

还有其他选择吗?

谢谢!
丹尼尔

【问题讨论】:

    标签: ruby-on-rails-3 rails-routing rails-console


    【解决方案1】:

    我刚刚在我的控制台中验证了它(Pry)

    # Send request with fake HTTP_HOST
    >>app.get(app.root_path, nil, {"HTTP_HOST" => "123.myapp.com"})
    >>#=>200
    
    # Then check if it works
    >>app.request.env
    >>#...
    >># "HTTP_HOST" : "123.myapp.com"
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-23
    • 2014-05-08
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 2011-10-10
    相关资源
    最近更新 更多