私はデコレータを使用する初心者であり、デコレータを正しく使用する方法と何が間違っているのかを理解するためにあなたの助けが必要です.
book_decorator.rb
class BookDecorator < ApplicationDecorator
delegate_all
def in_users_list?(user)
if user.books.exists?
true
end
end
end
ビュー/本/index.html.slim
- if book.in_users_list?(current_user)
- button_text = 'I've read this book'
... #depict some buttons and links
books_controller.rb
class BooksController < ApplicationController
expose(:book, attributes: :book_params, finder_parameter: :id)
expose_decorated(:book, decorator: BookDecorator)
...
私はこれらのチュートリアル(https://github.com/netguru/decent_decoration https://github.com/drapergem/draper#decorating-objects)に従っていますが、問題ないようですが、本のインデックスページにいるとき、それは言う
未定義のメソッド「in_users_list?」本の場合:0x007f6f4a0a4a18
デコレータのメソッドを使用する必要があることをまだ知らないと思いますが、どうすれば修正できますか? 何が間違っていたのか理解できません。問題を見つけて修正するのを手伝ってください! 前もって感謝します!