Why x-editable-rails gem throwing an error: undefined method `xeditable?'?
Asked Answered
G

1

5

I installed the gem x-editable for rails:

# x-editable
gem 'x-editable-rails'

I added the method xeditable? to the 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

But still getting an error:

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'

Where should I define the method xeditable? so that it starts working?

Update:

This is 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

This is 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

Now I get new error: same as xeditable?, but with can? (method undefined)

Glyn answered 18/12, 2013 at 15:24 Comment(6)
how did you call the method?Mukden
puts your xeditable? method to ApplicationHelper and try againBlanka
@majioa, I do not call the method, it is a part of auth mechanisms (as described by x-editable-rails)Glyn
@Monk_Code, it does not workGlyn
how did you add the method into a controller? show a part of code! into which controller did you add the method? If you've added the method into a helper, did you included the helper into its controller?Mukden
add helper_method :xeditable? below def xeditable?; true; endBlanka
M
8

Add helper_method :xeditable? in your 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
Magnification answered 18/12, 2013 at 16:10 Comment(5)
Thanks, it solves the problem with xeditable?, but the same problem appears with can? (as I see in the source they both are used in the if statement)Glyn
If you need additional, just write this: helper_method :xeditable?, :can? You don't need ApplicationHelper actually. See my edit.Magnification
helper_method :xeditable?, :can? doesn't work. Still the can? method is undefinedGlyn
I just defined the fake can? method (I don't use real auth yet): def can?(role, object) true # Or something like current_user.xeditable? end Glyn
Is everything ok after defining a new method for can??Magnification

© 2022 - 2024 — McMap. All rights reserved.