简体   繁体   English

Rails.root是否被Amazon AWS-SDK gem覆盖?

[英]Rails.root being overwritten by Amazon AWS-SDK gem?

I see this error: 我看到此错误:

undefined method `root' for AWS::Rails:Module

The corresponding line in my controller: 我的控制器中的相应行:

directory_name = Rails.root.join('public', @curAdmin.name)

This worked fine until I recently added the aws-sdk gem to my application to push static files and assets over to my S3 bucket. 在我最近将aws-sdk gem添加到我的应用程序中以将静态文件和资产推送到我的S3存储桶之前,这一直很好。

Now it seems like when I call "Rails" the application thinks I'm referring to an AWS class method. 现在看来,当我调用“ Rails”时,应用程序认为我正在引用AWS类方法。

I don't know how I tripped the system up to do this. 我不知道该如何使系统跳闸。

This will happen if you refer to Rails within the AWS namespace. 如果您在AWS名称空间中引用Rails则会发生这种情况。 You should be able back out of the namespace by prepending :: to the module - ie ::Rails.root.join('public', @curAdmin.name) 您应该可以通过在模块前面加上::来退出名称空间-即::Rails.root.join('public', @curAdmin.name)

I don't know why I tripped everything up - but if I remove the include at the top of the controller: 我不知道为什么将所有内容都绊倒了-但是如果我删除了控制器顶部的include:

#include AWS

And then I refer to such methods directly as: 然后,我直接将此类方法称为:

s3 = AWS::S3.new
bucket = s3.buckets['my_bucket_here']

It works ok. 可以。 I'd still like to know what I did wrong. 我仍然想知道我做错了什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM