基于导轨中的域设置全局实例变量
我有一个单一的铁路应用程序,目前正在通过让我们说 https://www.domain1.com ,我想启用第二个域访问该应用程序,可以说 https://www.domain2.com ,然后将设置全局实例变量。
然后,我想使用此实例变量来控制页面上的某些内容,例如内容,样式和图像。
有什么想法我如何实现这一目标?
I have a single Rails application that is currently being accessed via lets say https://www.domain1.com and I would like to enable the application to be accessed by a second domain, lets say https://www.domain2.com which would then set a global instance variable.
I would then like to use this instance variable to control certain things on the page such as content, styles and images.
Any ideas how I could achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,
全局变量和实例变量是不同的。实例变量范围为类的实例,并且全局变量具有全局范围。最小化范围是一个很好的经验法则。
对于控制器,视图或助手的Rails代码,您只需直接调用
request.domain
而不是将其分配给变量。E.g.
A global variable and an instance variable are different things. An instance variable is scoped to an instance of a class, and a global variable has a global scope. It's a good rule of thumb to minimize scope.
In the case of Rails code in controllers, views or helpers, you can just call
request.domain
directly instead of assigning that to a variable.