2013-12-18 3 views
3

Я установил камень х редактируемые для рельсов:Почему x-editable-rails gem выдает ошибку: неопределенный метод `xeditable? '?

# 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?, чтобы он начал работать?

Update:

Это 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? (метод неопределенном)

+0

как вы назвали метод? –

+0

ставит ваш метод «xeditable?» На ApplicationHelper и повторяет попытку –

+0

@majioa, я не называю этот метод, он является частью механизмов auth (как описано x-editable-rails) – static

ответ

5

Добавить 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 
+0

Спасибо, он решает проблему с 'xeditable?', но та же проблема появляется с 'can?' (как я вижу в источнике, оба они используются в инструкции if) – static

+0

Если вам нужно дополнительное , просто напишите это: 'helper_method: xeditable ?,: может?' На самом деле вам не нужно 'ApplicationHelper'. См. Мое редактирование. – Victor

+0

'helper_method: xeditable ?,: can?' Не работает. Тем не менее метод 'can?' Не определен – static

Смежные вопросы