本文介绍了为什么x-editable-rails gem抛出错误:未定义的方法"xeditable?"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我安装了可编辑的gem x for rails:
I installed the gem x-editable for rails:
# x-editable
gem 'x-editable-rails'
我将方法xeditable?
添加到了ActionController
:
# Add a helper method to your controllers to indicate if x-editable should be enabled.
def xeditable?
true # Or something like current_user.xeditable?
end
但仍然出现错误:
ActionView::Template::Error (undefined method `xeditable?' for #<#<Class:0x007f9012e30f68>:0x007f9012ee9e78>):
14:
15: .panel-body
16: /a.doc_title.editable id='doc_title_12345' data-name="doc[title]" data-title="Enter doc title" data-type="text" data-url='/docs/12345' href='#doc_title_12345' = doc.title
17: = editable doc, :title
18:
app/views/docs/_single_doc_in_accordion.html.slim:17:in `_app_views_docs__single_doc_in_accordion_html_slim__2506304306156466629_70128411437560'
app/views/docs/index.html.slim:52:in `_app_views_docs_index_html_slim___3263534966956214695_70128384677640'
我应该在哪里定义方法xeditable?
,以便它开始起作用?
Where should I define the method xeditable?
so that it starts working?
这是application_controller.rb
:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
这是application_helper.rb
:
module ApplicationHelper
# Add a helper method to your controllers to indicate if x-editable should be enabled.
def xeditable?
true # Or something like current_user.xeditable?
end
end
现在我得到新的错误:与xeditable?
相同,但是具有can?
(方法未定义)
Now I get new error: same as xeditable?
, but with can?
(method undefined)
推荐答案
在ApplicationController.rb
中添加helper_method :xeditable?
:
class ApplicationController < ActionController::Base
helper_method :xeditable?
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
# Add a helper method to your controllers to indicate if x-editable should be enabled.
def xeditable?
true # Or something like current_user.xeditable?
end
end
这篇关于为什么x-editable-rails gem抛出错误:未定义的方法"xeditable?"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!