我正在尝试使用 ActiveStorage 和 aws s3 将已折旧的(对于 Rails 5.2)回形针替换为图像上传。我在用着this http://guides.rubyonrails.org/active_storage_overview.html#direct-uploads指南和 GoRails 剧集,但遇到了我无法解析的控制台错误。我的表单上的一切看起来都不错,但是当我提交时,我在控制台中看到:
activestorage.self-6e8d967adecc8b2a7259df0f51ef5b6f171c33267c7d149a474beccd90c68697.js?body=1:1 POST http://localhost:3000/rails/active_storage/direct_uploads 500 (Internal Server Error)
我的身上有这个blogs#new
_form.html.erb
:
<div class="form-group">
<%= f.label "Picture" %>
<%= f.file_field :image, direct_upload: true %>
</div>
我将其放入我的模型中:
has_one_attached :image
I have :image
在我的参数中
def blog_params
params.require(:blog).permit(:title, :teaser, :body, :user_id, :tag_list, :link_text, :link_filename, :pillars_id, :image)
end
我把这个添加到我的storage.yml
:
Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
service: S3
access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
region: us-west-1
bucket: nameofbucket
在我的开发环境中:
config.active_storage.service = :amazon
我包含了上面链接的 RubyOnRails 指南中的 javascript/css。有人看到这个错误是从哪里来的吗?我对调试控制台错误不太有经验,因此任何信息或智慧都值得赞赏。
附加信息
这是我的 Rails 控制台中发生的错误:
LoadError - Unable to autoload constant ActiveStorage::Blob::Analyzable, expected /Users/lizbayardelle/.rvm/gems/ruby-2.3.3/gems/activestorage-5.2.0/app/models/active_storage/blob/analyzable.rb to define it:
::1 - - [12/Jul/2018:13:56:05 PDT] "POST /rails/active_storage/direct_uploads HTTP/1.1" 500 7784
http://localhost:3000/blogs/new -> /rails/active_storage/direct_uploads
其他注意事项
当我尝试创建没有图像的博客时,出现此错误:
undefined method `[]=' for nil:NilClass