下記の記事を参考にマークダウン記法を取り入れようとしています。そこでエラーに遭遇してしまいました。このエラーを解消しマークダウンを実装したいです!!
app/helpers/application_helper.rb
rb
1module ApplicationHelper 2 require "redcarpet" 3 require "coderay" 4 def page_title 5 title = "Wakatta" 6 title = @page_title + "-" + title if @page_title 7 title 8 end 9 def menu_link_to(text, path, options = {}) 10 content_tag :li do 11 condition = options[:method] || !current_page?(path) 12 13 link_to_if(condition, text, path, options) do 14 content_tag(:span, text) 15 end 16 end 17 end 18 19 20 def markdown(text) 21 html_render = HTMLwithCoderay.new(filter_html: true, hard_wrap: true) 22 options = { 23 autolink: true, 24 space_after_headers: true, 25 no_intra_emphasis: true, 26 fenced_code_blocks: true, 27 tables: true, 28 hard_wrap: true, 29 xhtml: true, 30 lax_html_blocks: true, 31 strikethrough: true 32 } 33 renderer = Redcarpet::Render::HTML.new(options) 34 markdown = Redcarpet::Markdown.new(renderer, extensions) 35 markdown.render(text).html_safe 36 end 37 38 class HTMLwithCoderay < Redcarpet::Render::HTML 39 def block_code(code, language) 40 language = language.split(':')[0] 41 42 case language.to_s 43 when 'rb' 44 lang = 'ruby' 45 when 'yml' 46 lang = 'yaml' 47 when 'css' 48 lang = 'css' 49 when 'html' 50 lang = 'html' 51 when '' 52 lang = 'md' 53 else 54 lang = language 55 end 56 57 CodeRay.scan(code, lang).div 58 end 59 end 60 61end
gemfile
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.6.5' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 6.0.1' 8# Use sqlite3 as the database for Active Record 9gem 'sqlite3', '~> 1.4' 10# Use Puma as the app server 11gem 'puma', '~> 4.1' 12# Use SCSS for stylesheets 13gem 'sass-rails', '>= 6' 14# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker 15gem 'webpacker', '~> 4.0' 16# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 17gem 'turbolinks', '~> 5' 18# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 19gem 'jbuilder', '~> 2.7' 20# Use Redis adapter to run Action Cable in production 21# gem 'redis', '~> 4.0' 22# Use Active Model has_secure_password 23gem 'bcrypt', '~> 3.1.7' 24 25gem "mini_magick" 26gem 'redcarpet', '~> 2.3.0' 27gem 'coderay' 28
エラーメッセージの詳細はこれだけでしょうか。
Started GET "/articles/42" for ::1 at 2019-12-20 23:30:31 +0900
(0.2ms) SELECT sqlite_version(*)
LoadError (cannot load such file -- redcarpet):
これがログです!
app/helpers/application_helper.rb:2:in `<module:ApplicationHelper>'
app/helpers/application_helper.rb:1:in `<main>'
app/controllers/application_controller.rb:1:in `<main>'
app/controllers/articles_controller.rb:1:in `<main>'
回答2件
あなたの回答
tips
プレビュー