【发布时间】:2017-07-31 19:15:06
【问题描述】:
不知道为什么我在实施 gem x_editable_rails 以允许在不将用户带到单独的编辑页面的情况下编辑 cmets 时收到此 error message。
x_editable_rails 演示应用程序显示,也许正确的方法应该是 <%= editable @comment, :content %>,,但因为我在循环 @cmets 实例变量中的所有 cmets,这样做也会引发错误。
编辑
我将代码行从 <%= editable @comments.comment %> 更改为 <%= editable [comment.article, comment], :content, url: edit_article_comment_path(comment.article, comment) %> 现在,它的显示
undefined method `xeditable?' error.
我已经添加了下面的帮助方法并将这个(helper_method :xeditable?)添加到应用程序控制器。 (我不使用cancan,所以我添加了一个虚拟罐头?正如stackoverflow post所建议的那样。
module ApplicationHelper
def xeditable?
current_user.xeditable?
end
def can?(role, object)
true
end
end
_cmets.html.erb
<% @comments.each do |comment| %>
<%= editable [comment.article, comment], :content, url: edit_article_comment_path(comment.article, comment) %>
<%= link_to "Delete comment", [comment.article, comment], method: :delete %>
<%= link_to "Edit comment", edit_article_comment_path(comment.article, comment) %>
<% end %>
routes.rb
resources :articles do
resources :comments
end
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-5