简体   繁体   English

Rails:在heroku上使用回形针和AWS的语法错误

[英]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. 我正在使用回形针,devise,aws和heroku在Rails应用程序上显示我的图片。 It was working fine until I changed my app/assets/application.js and my controllers/users/sessions_controller.rb 在我更改app / assets / application.js和controllers / users / sessions_controller.rb之前,它一直运行良好。

Note: I did not change a thing in my config/environments/production.rb 注意:我没有更改config / environments / production.rb中的任何内容

However I get an syntax error message, when I am using the heroku run rails console. 但是,当我使用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 / 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) 在javascripts / application.js中,我将// = require引导程序放在jquery_ujs下面(它首先在底部)

//= 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 我已经设计出了一个sessions_controller,以便用户登录时,我想更改数据库中的某些内容。

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. 我检查了您的代码,发现这是您的production.rb代码的语法错误。

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'),
  }
}

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

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