加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 为什么x-editable-rails gem抛出错误:未定义

发布时间:2020-12-17 03:31:55 所属栏目:百科 来源:网络整理
导读:我安装了gem x-editable for rails: # x-editablegem '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 l
我安装了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方法?它开始工作?

更新:

这是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相同?但是可以吗? (方法未定义)

解决方法

添加helper_method:xeditable?在ApplicationController.rb中:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读