[英]Rails: Syntax error using paperclip and aws on heroku
我正在使用回形針,devise,aws和heroku在Rails應用程序上顯示我的圖片。 在我更改app / assets / application.js和controllers / users / sessions_controller.rb之前,它一直運行良好。
注意:我沒有更改config / environments / production.rb中的任何內容
但是,當我使用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,
^
在我的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'),
}
}
我改變了什么:
在javascripts / application.js中,我將// = require引導程序放在jquery_ujs下面(它首先在底部)
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require owl.carousel
//= require_tree .
我已經設計出了一個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
我檢查了您的代碼,發現這是您的production.rb代碼的語法錯誤。
您正在使用哈希,但最后缺少逗號(,)。 因此,請用以下幾行替換您的代碼。
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.