0
votes

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
1
Regardless of what you recall changing, the code excerpt from your production.rb is not valid Ruby: you can't use = inside of a hash declaration unless it's part of a string or part of the value statement.coreyward
@coreyward: I feel so stupid, that was it (Vijay had the same solution as you). Thank you. However it's still strange that the code worked before, since I did not touch production.rb. Nevertheless, thanks :).OhDaeSu
It might have been that the changes to production.rb had been made previously but unsaved (and/or uncommitted). This is one reason I always review a diff before I commit, and double check with git status as well, even if it's a single character being changed. #protipcoreyward
@coreyward: Hehe, thanks, I will keep that in mind :).OhDaeSu

1 Answers

1
votes

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