8

I'm trying to replace the depreciated (for Rails 5.2) paperclip with image uploads using ActiveStorage and aws s3. I'm using this guide and the GoRails episode on it, but have hit a console error I can't parse. Everything looks okay on my form, but when I go to submit I get this in my console:

activestorage.self-6e8d967adecc8b2a7259df0f51ef5b6f171c33267c7d149a474beccd90c68697.js?body=1:1 POST http://localhost:3000/rails/active_storage/direct_uploads 500 (Internal Server Error)

I have this on my blogs#new _form.html.erb:

<div class="form-group">
  <%= f.label "Picture" %>
  <%= f.file_field :image, direct_upload: true %>
</div>

I put this in my model:

has_one_attached :image

I have :image in my params

def blog_params
  params.require(:blog).permit(:title, :teaser, :body, :user_id, :tag_list, :link_text, :link_filename, :pillars_id, :image)
end

I added this to my 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

And this in my development environment:

config.active_storage.service = :amazon

I included the javascript/css from the RubyOnRails Guides linked above. Anyone see where this error is coming from? I'm not too experienced with debugging console errors, so any info or wisdom is appreciated.

ADDITIONAL INFORMATION

Here's the error that happens in my Rails Console:

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

Other Note

When I try to create a blog without an image I get this error:

undefined method `[]=' for nil:NilClass
Liz
  • 1,369
  • 2
  • 26
  • 61
  • That's from your browser console? If so, what's in your rails console? – jvillian Jul 12 '18 at 22:11
  • @jvillian Good question! (Sorry, duh.) I added that error to the OP as well. – Liz Jul 12 '18 at 22:35
  • Did try the googlies with [Unable to autoload constant ActiveStorage::Blob::Analyzable](https://www.google.com/search?q=Unable+to+autoload+constant+ActiveStorage%3A%3ABlob%3A%3AAnalyzable)? It looks like there might be some promising leads there. – jvillian Jul 12 '18 at 22:40
  • @jvillian I did try the googlies (and am totally stealing that phrase) with that. There is a lot there, showing this is a common problem, but I still can't get it to work. – Liz Jul 13 '18 at 02:28
  • So in your gemfile you have something like: `gem "aws-sdk-s3", require: false` and ran `bundle update && bundle install` with no success? – Mark Merritt Jul 15 '18 at 02:11
  • @MarkMerritt Yes, I have `gem 'aws-sdk-s3', require: false` and `gem 'aws-sdk' , '~> 3'`. Have updated and installed. – Liz Jul 15 '18 at 02:13
  • Hey, can you open your console, type : `ENV["AWS_ACCESS_KEY_ID"]` and `ENV["AWS_SECRET_ACCESS_KEY"]` and make sure the variables do not return nil ? – Uelb Jul 21 '18 at 19:35
  • `rails active_storage:install` & `rake db:migrate`. Did you run this to setup the storage? – Tom Jan 02 '19 at 14:41
  • Did you check this question? https://stackoverflow.com/questions/52358427/unable-to-autoload-constant-activestorageblobanalyzable-error-with-rails-5-2 – Fatih Apr 21 '19 at 15:24

0 Answers0