简体   繁体   中英

Rails: Syntax error using paperclip and aws on heroku

I am using paperclip, devise, aws and heroku to show my pictures on my Rails app. It was working fine until I changed my app/assets/application.js and my controllers/users/sessions_controller.rb

Note: I did not change a thing in my config/environments/production.rb

However I get an syntax error message, when I am using the heroku run rails console.

Running rails console on ⬢ immense-spire-90312... up, run.8450 (Free)
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require': /app/config/environments/production.rb:88: syntax error, unexpected '\n', expecting => (SyntaxError)
/app/config/environments/production.rb:92: syntax error, unexpected ':', expecting keyword_end
storage: :s3,
        ^

In my config/environments/production.rb

config.paperclip_defaults = {
  Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
  Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
  Paperclip::Attachment.default_options[:s3_host_name] = 's3-eu-central-1.amazonaws.com'

  # The syntax error seems to be here: 
  storage: :s3,
  s3_credentials: {
    bucket: ENV.fetch('S3_BUCKET_NAME'),
    access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    s3_region: ENV.fetch('AWS_REGION'),
  }
}

What I've changed:

In javascripts/application.js I put the //= require bootstrap under the jquery_ujs (it was at the bottom at first)

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require owl.carousel
//= require_tree .

And I've created a sessions_controller in devise, so that when a user logs in, I want to change something in the database

class Users::SessionsController < Devise::SessionsController

  def create
    super do |user| 
      user.randomized_fakeposts.delete_all
      # Note: A fakeposts consists of an image_url which is taken from aws.
      Fakepost.all.each do |fp|
        user.randomized_fakeposts.new(fakepost: fp)
      end
      user.save
    end
  end
end

I reviewed your code and found this is syntax error with your production.rb code.

You are using hash but missed comma(,) at the end. so please replace your code with following lines.

config.paperclip_defaults = {
  :url => ':s3_domain_url',
  :path => '/:class/:attachment/:id_partition/:style/:filename',
  :s3_host_name] => 's3-eu-central-1.amazonaws.com',

  # The syntax error seems to be here: 
  storage: :s3,
  s3_credentials: {
    bucket: ENV.fetch('S3_BUCKET_NAME'),
    access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
    secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
    s3_region: ENV.fetch('AWS_REGION'),
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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