Rails 5.2アプリで作業していて、active_storageをインストールしてセットアップしましたが、Rails資格情報を編集または表示できません。
これはエラーの出力です
ben@ben-VirtualBox:~/Desktop/benbagley$ EDITOR="atom --wait" Rails credentials:edit
Traceback (most recent call last):
38: from bin/Rails:3:in `<main>'
37: from bin/Rails:3:in `load'
36: from /home/ben/Desktop/benbagley/bin/spring:15:in `<top (required)>'
35: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
34: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
33: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
32: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
31: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
30: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
29: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
28: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/Rails.rb:28:in `call'
27: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/Rails.rb:28:in `load'
26: from /home/ben/Desktop/benbagley/bin/Rails:9:in `<top (required)>'
25: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
24: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
23: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
22: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
21: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
20: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
19: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
18: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/bootsnap-1.3.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
17: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/railties-5.2.0/lib/Rails/commands.rb:18:in `<main>'
16: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/railties-5.2.0/lib/Rails/command.rb:46:in `invoke'
15: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/railties-5.2.0/lib/Rails/command/base.rb:65:in `perform'
14: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
13: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
12: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
11: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/railties-5.2.0/lib/Rails/commands/credentials/credentials_command.rb:26:in `edit'
10: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/railties-5.2.0/lib/Rails/command/helpers/editor.rb:26:in `catch_editing_exceptions'
9: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/railties-5.2.0/lib/Rails/commands/credentials/credentials_command.rb:27:in `block in edit'
8: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/railties-5.2.0/lib/Rails/commands/credentials/credentials_command.rb:50:in `change_credentials_in_system_editor'
7: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:54:in `change'
6: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/encrypted_configuration.rb:21:in `read'
5: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:42:in `read'
4: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/encrypted_file.rb:79:in `decrypt'
3: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify'
2: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:157:in `decrypt_and_verify'
1: from /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:183:in `_decrypt'
/home/ben/.rbenv/versions/2.5.0/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)
ただし、新しいアプリを生成すると、資格情報を編集して表示できます。マスターキーを変更していないので、このアプリの問題は不明です。
編集::
私も得ています
ben@ben-VirtualBox:~/Desktop/benbagley$ Rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `Rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (Ruby 2.5.0-p0), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Started GET "/" for 127.0.0.1 at 2018-05-20 14:39:37 +0100
(5.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
↳ /home/ben/.rbenv/versions/2.5.0/lib/Ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
Processing by PagesController#welcome as HTML
Rendering pages/welcome.html.erb within layouts/application
Rendered pages/welcome.html.erb within layouts/application (1.0ms)
Rendered layouts/_navigation.html.erb (0.6ms)
Rendered layouts/_footer.html.erb (0.3ms)
Completed 200 OK in 1149ms (Views: 1136.3ms | ActiveRecord: 0.0ms)
Started GET "/works" for 127.0.0.1 at 2018-05-20 14:39:41 +0100
Processing by WorksController#index as HTML
Rendering works/index.html.erb within layouts/application
Work Load (1.7ms) SELECT "works".* FROM "works"
↳ app/views/works/index.html.erb:5
ActiveStorage::Attachment Load (1.7ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 2], ["record_type", "Work"], ["name", "header_image"], ["LIMIT", 1]]
↳ app/views/works/index.html.erb:7
Rendered works/index.html.erb within layouts/application (63.0ms)
Completed 500 Internal Server Error in 71ms (ActiveRecord: 15.9ms)
ActionView::Template::Error (ActiveSupport::MessageEncryptor::InvalidMessage):
4:
5: <% @works.each do |work| %>
6: <section class="max-w-md w-full lg:flex mb-2 shadow-md">
7: <section class="h-48 lg:h-auto lg:w-64 flex-none bg-cover rounded-t lg:rounded-t-none lg:rounded-l text-center overflow-hidden" style="background-image: url('<%= polymorphic_url work.header_image %>'); background-position: 50%; background-repeat: no-repeat;" title="<%= work.title %>">
8: </section>
9: <section class="border-r border-b border-l border-champagne-dark lg:border-l-0 lg:border-t bg-champagne-dark rounded-b lg:rounded-b-none lg:rounded-r p-4 flex flex-col justify-between leading-normal">
10: <section class="mb-6">
(erb):12:in `<main>'
app/views/works/index.html.erb:7:in `block in _app_views_works_index_html_erb__3122246537996604426_69953460278620'
app/views/works/index.html.erb:5:in `_app_views_works_index_html_erb__3122246537996604426_69953460278620'
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2018-05-20 14:39:55 +0100 ===
- Goodbye!
Exiting
資格情報を使用する行をコメントにしてEDITOR="atom --wait" Rails credentials:edit
を実行します(編集後、コメントを外してください)。これが機能しない場合は、credentials.yml.encを削除して、再試行してください。
Credentials.yml.encとmaster.keyを移動または削除して、Rails credentials:edit
を再実行します。これでうまくいきました。
私も同じ問題を抱えていました。 EDITOR="atom --wait" Rails credentials:edit
を実行するだけでは不十分であることがわかりました。
暗号化された資格情報で最初に定義せずにソースコードでRails.application.credentials.some_api_key
を設定すると、資格情報ファイルを編集したり、表示したりできなくなります。これは、認証情報を復号化するためにアプリケーション全体を実行する必要があるためと考えられます。