Search code examples
ruby-on-railsproduction

Running a rails server in production locally (InvalidMessage error)


I'm running Ruby 2.5.1 and Rails 5.2.0. I ran rails s -e production, and it gives this error:

/home/roy/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:206:in `rescue in_decrypt': ActiveSupport::MessageEncryptor::InvalidMessage
(ActiveSupport::MessageEncryptor::InvalidMessage)

How do I do this properly?


EDIT: The same error appears whenever I try to edit the credentials file using

EDITOR="nano --wait" bin/rails credentials:edit

Also I realized that I didn't create a production database yet so I tried that using

RAILS_ENV=production bundle exec rails db:reset

(I know db:reset is a bit redundant but it should work trying to create, migrate and seed a server)

Sadly I get the same kind of error (InvalidMessage error)

Unsupported rails environment for compass
rake aborted!
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/home/roy/apps/myappname/config/environment.rb:5:in `<main>'
/home/roy/.rbenv/versions/2.5.1/bin/bundle:23:in `load'
/home/roy/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'

Caused by:
OpenSSL::Cipher::CipherError: 
/home/roy/apps/myappname/config/environment.rb:5:in `<main>'
/home/roy/.rbenv/versions/2.5.1/bin/bundle:23:in `load'
/home/roy/.rbenv/versions/2.5.1/bin/bundle:23:in `<main>'
Tasks: TOP => db:create => db:load_config => environment

Solution

  • Okay I got it working finally.

    I simply deleted my master.key and credentials.yml.enc files and then ran

    bin/rails credentials:edit
    

    Which created new files. After that everything worked fine.

    I don't really understand why it works though. Can anyone give a good explanation for this?