How to use decorator in rails correctly? -
i'm newbie in using decorators , need understand how use right , doing wrong.
book_decorator.rb
class bookdecorator < applicationdecorator delegate_all def in_users_list?(user) if user.books.exists? true end end end
views/books/index.html.slim
- if book.in_users_list?(current_user) - button_text = 'i've read book' ... #depict buttons , links
books_controller.rb
class bookscontroller < applicationcontroller expose(:book, attributes: :book_params, finder_parameter: :id) expose_decorated(:book, decorator: bookdecorator) ...
i've followed these tutorials (https://github.com/netguru/decent_decoration https://github.com/drapergem/draper#decorating-objects) , seems fine, when i'm on books index page, says
undefined method `in_users_list?' book:0x007f6f4a0a4a18
i suppose still doesn't know should use method decorator, how fix it? can't understand i've done wrong, please find , fix problem! thank in advance!
well, had add expose_decorated(:books) in books_controller. thing it's because i'm using in index method, books (not book) should decorated