Rails 布料 gem 和 Ajax/JS
Rails draper gem with Ajax/JS
我正在使用 draper 并想在视图中使用其中一个装饰器。
使用 HTML 一切正常,但装饰器在 Ajax 版本中不起作用 - 我收到未定义方法错误。
在 CommentDecorator 中:
delegate_all
def comment_author
"#{user.firstname} #{user.lastname}"
end
在视图中:
comment.comment_author
我正在使用曝光,所以我不需要视图中的实例变量。
你可以使用
comment.decorate.comment_author
我正在使用 draper 并想在视图中使用其中一个装饰器。
使用 HTML 一切正常,但装饰器在 Ajax 版本中不起作用 - 我收到未定义方法错误。
在 CommentDecorator 中:
delegate_all
def comment_author
"#{user.firstname} #{user.lastname}"
end
在视图中:
comment.comment_author
我正在使用曝光,所以我不需要视图中的实例变量。
你可以使用
comment.decorate.comment_author