私はデコレータの使用に初心者です。私はデコレータの使用方法を理解し、間違っていることを理解するためにあなたの助けが必要です。 index.html.slimデコレータをレールに正しく使うには?
book_decorator.rb
class BookDecorator < ApplicationDecorator
delegate_all
def in_users_list?(user)
if user.books.exists?
true
end
end
end
ビュー/書籍/
- 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_decorationhttps://github.com/drapergem/draper#decorating-objects)に続いてきたし、大丈夫のようですが、私はブックインデックスページ上だとき、それは
未定義のメソッド `in_users_list言います?」ブックの場合:0x007f6f4a0a4a18
デコレータのメソッドを使用する必要がありますが、それを修正する方法はまだわからないと思いますか?私が間違ったことを理解できない、問題を見つけて解決するのを手伝ってください! ありがとうございます!