事象
- kaminariを導入した後に、Bootstrapの見た目にしたいということで
bin/rails g kaminari:views bootstrap4
を叩いてファイル生成するのですが、以下のようなエラーとなりました。
$ bin/rails g kaminari:views bootstrap4
Running via Spring preloader in process 2526
Traceback (most recent call last):
37: from -e:1:in `<main>'
36: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
35: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
34: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `load'
33: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
32: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:285:in `block in load'
31: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
30: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
29: from /Users/user_name/book_match/bin/rails:9:in `<top (required)>'
28: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
27: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
26: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
25: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
24: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
23: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
22: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
21: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
20: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<top (required)>'
19: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/command.rb:46:in `invoke'
18: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/command/base.rb:65:in `perform'
17: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
16: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
15: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
14: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/commands/generate/generate_command.rb:26:in `perform'
13: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.3/lib/rails/generators.rb:276:in `invoke'
12: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
11: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
10: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
9: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
8: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
7: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
6: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
5: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
4: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/kaminari-0.17.0/lib/generators/kaminari/views_generator.rb:27:in `copy_or_fetch'
3: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/kaminari-0.17.0/lib/generators/kaminari/views_generator.rb:39:in `themes'
2: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/kaminari-0.17.0/lib/generators/kaminari/views_generator.rb:99:in `get_files_in_master'
1: from /Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/kaminari-0.17.0/lib/generators/kaminari/views_generator.rb:99:in `open'
/Users/user_name/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/kaminari-0.17.0/lib/generators/kaminari/views_generator.rb:99:in `initialize': No such file or directory @ rb_sysopen - https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master (Errno::ENOENT)
対応策
- 参考:rails g kaminari:views bootstrap3が実行できない
- こちらのページを参考に、また、以前別プロジェクトでkaminariを導入していた時のライブラリのジェネレーターファイルと比較してみたところ、以下のような
require 'open-uri'
の記述がありませんでした。
- こちらのページを参考に、また、以前別プロジェクトでkaminariを導入していた時のライブラリのジェネレーターファイルと比較してみたところ、以下のような
- ということで、
require 'open-uri'
を以下のように追記してから再度実行してみると、上手くいきました。
lib/generators/kaminari/views_generator.rb
module Kaminari
module Generators
require 'open-uri' # この行を追記
class ViewsGenerator < Rails::Generators::NamedBase
$ bin/rails g kaminari:views bootstrap4
Running via Spring preloader in process 2545
downloading app/views/kaminari/_first_page.html.slim from kaminari_themes...
create app/views/kaminari/_first_page.html.slim
downloading app/views/kaminari/_gap.html.slim from kaminari_themes...
create app/views/kaminari/_gap.html.slim
downloading app/views/kaminari/_last_page.html.slim from kaminari_themes...
create app/views/kaminari/_last_page.html.slim
downloading app/views/kaminari/_next_page.html.slim from kaminari_themes...
create app/views/kaminari/_next_page.html.slim
downloading app/views/kaminari/_page.html.slim from kaminari_themes...
create app/views/kaminari/_page.html.slim
downloading app/views/kaminari/_paginator.html.slim from kaminari_themes...
create app/views/kaminari/_paginator.html.slim
downloading app/views/kaminari/_prev_page.html.slim from kaminari_themes...
create app/views/kaminari/_prev_page.html.slim