状況
- ruby: 2.4.5
- rails: 5.0.0.1
- kaminari-core-1.2.2
以下のコマンド実行するとエラー文が出る
rails g kaminari:views bootstrap4
/usr/local/bundle/gems/kaminari-core-1.2.2/lib/generators/kaminari/views_generator.rb:117:in `get_files_in_master': private method `open' called for URI:Module (NoMethodError)
views_generator.rb 一部抜粋
views_generator.rb
module GitHubApiHelper
require 'open-uri'
def get_files_in_master
master_tree_sha = URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
ActiveSupport::JSON.decode(json.read)['object']['sha']
end
URI.open('https:i//api.github.com/repos/amatsuda/kaminari_themes/git/trees/' + master_tree_sha + '?recursive=1') do |json|
blobs = ActiveSupport::JSON.decode(json.read)['tree'].find_all {|i| i['type'] == 'blob' }
blobs.map do |blob|
[blob['path'], blob['sha']]
end
end
end
module_function :get_files_in_master
def get_content_for(path)
URI.open('https://api.github.com/repos/amatsuda/kaminari_themes/contents/' + path) do |json|
Base64.decode64(ActiveSupport::JSON.decode(json.read)['content'])
end
end
module_function :get_content_for
end
解決策
Rubyバージョン2.6よりURI.open('url')
それ以下はopen('url')
Rubyのバージョンを上げるかviews_generator.rbを修正する。
もしくはkaminari 1.1.1を指定する。
今回はviews_generator.rbを修正した
修正後 views_generator.rb
module GitHubApiHelper
require 'open-uri'
def get_files_in_master
master_tree_sha = open('https://api.github.com/repos/amatsuda/kaminari_themes/git/refs/heads/master') do |json|
ActiveSupport::JSON.decode(json.read)['object']['sha']
end
open('https:i//api.github.com/repos/amatsuda/kaminari_themes/git/trees/' + master_tree_sha + '?recursive=1') do |json|
blobs = ActiveSupport::JSON.decode(json.read)['tree'].find_all {|i| i['type'] == 'blob' }
blobs.map do |blob|
[blob['path'], blob['sha']]
end
end
end
module_function :get_files_in_master
def get_content_for(path)
open('https://api.github.com/repos/amatsuda/kaminari_themes/contents/' + path) do |json|
Base64.decode64(ActiveSupport::JSON.decode(json.read)['content'])
end
end
module_function :get_content_for
end
プロジェクト配下にviews_generator.rbを作成して以下のコマンドをDockerfile内、RUN bundle install
後に追加した。
COPY views_generator.rb /usr/local/bundle/gems/kaminari-core-1.2.2/lib/generators/kaminari/