我正在使用paperclip,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
答案 0 :(得分:1)
我查看了您的代码,发现这是您的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'),
}
}