子网域和本地安装的Rails应用 [英] Subdomains and locally installed Rails app

查看:87
本文介绍了子网域和本地安装的Rails应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚我所忽略的是什么,也许是显而易见的或缺乏理解.

I can't figure out what I'm overlooking, perhaps it's obvious or lack of understanding.

我正在使用的应用使用了托管服务器上正常工作的子域.我认为本地安装会引发路由方面的一些问题,因此我阅读了有关对/etc/hosts进行更改并使用Ghost gem的信息.两者似乎都可以正常工作,即localhost:3000/变为myapp.local:3000,但我不知道如何登录子域帐户.这是一个示例...

The app I'm working with uses subdomains which on the hosting server work properly. I figured locally installing would kick up some issues around routing, so I read up on making changes to /etc/hosts and using the Ghost gem. Both seem to work fine i.e. localhost:3000/ becomes myapp.local:3000 but I don't understand how to go about logging into a subdomain account. Here's an example...

  • myapp.local:3000/session/new =该应用程序的默认登录页面
  • myapp.local:3000/signup =默认注册页面
    • 我可以在这里创建一个帐户,例如Sub1
    • 显示的感谢页面带有对sub1.myapp.com的引用,该引用指向托管的应用程序(本地数据库也显示了该域)
    • myapp.local:3000/session/new = the default login page for the app
    • myapp.local:3000/signup = default signup page
      • I can create an account here e.g. Sub1
      • The thank you page is shown w/ the reference to sub1.myapp.com which points to the hosted app (the local db shows this domain as well)
      • 登录尝试返回此域无效.这似乎是有道理的,因为本地数据库在托管服务器上将URL显示为sub1.myapp.com.

      所以我的问题是,是否存在可以用于开发的本地变通方法,或者在此过程中我完全错过了一个基本概念?

      So my question is whether there's a local workaround that I can use for development or have I totally missed a fundamental concept along the way?

      推荐答案

      您可能只想尝试将实际的dot com放在/etc/hosts文件中.

      you might just want to try putting the actual dot com in your /etc/hosts file.

      即:

      
      127.0.0.1 sub1.myapp.com
      127.0.0.1 myapp.com
      127.0.0.1 anyothersubdomains.myapp.com
      

      这通常会欺骗您的计算机,使您认为它是所有这些计算机的宿主,因此您无法再通过Web浏览器访问真实站点.

      what this usually does is trick your computer into thinking it is the host of all of those, so you can't go to the real site anymore in a web browser.

      如果您确实希望它是.local,以便在处理本地副本时可以参考真正的在线网站,则可能应该查看一下app/controllers/application_controller.rb(有时是application.rb ),并在其中寻找有助于确定根据子域要执行的操作的逻辑.也许它的硬编码只是寻找.com之类的东西.

      if you do want it to be .local, presumably so that you can refer to the real online site while working on a local copy, you should probably take a look in app/controllers/application_controller.rb (sometimes application.rb) and look for logic in there that helps determine what to do depending on the subdomain. maybe its hard coded to only look for a .com or something.

      这篇关于子网域和本地安装的Rails应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆