rails 模块中未定义的方法
rails undefined method at module
我的 rails 模块中有一个方法,这是我的模块
module Searchable
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
index_name Rails.application.class.parent_name.underscore
puts Rails.application.class.parent_name.underscore
document_type self.name.downcase
# you get an error if this shit run first
module ClassMethods
def setting_index(arguments)
settings index: {number_of_shards: 1} do
... more code ...
顺便说一句。当我第一次尝试执行此方法(setting_index)时出现错误。
但是当我再次尝试执行时,这个错误消失了..
谁能解决这个问题并给我一个明确的答案...
感谢您的关心:)
require 'active_support/concern'
module Callable
extend ActiveSupport::Concern
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
included do
end
module ClassMethods
def setting_index(arguments)
settings index: {number_of_shards: 1} do
... more code ...
end
end
我认为您需要将包含的模块放在包含的 do 块之外。
我的 rails 模块中有一个方法,这是我的模块
module Searchable
extend ActiveSupport::Concern
included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
index_name Rails.application.class.parent_name.underscore
puts Rails.application.class.parent_name.underscore
document_type self.name.downcase
# you get an error if this shit run first
module ClassMethods
def setting_index(arguments)
settings index: {number_of_shards: 1} do
... more code ...
顺便说一句。当我第一次尝试执行此方法(setting_index)时出现错误。
但是当我再次尝试执行时,这个错误消失了..
谁能解决这个问题并给我一个明确的答案... 感谢您的关心:)
require 'active_support/concern'
module Callable
extend ActiveSupport::Concern
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
included do
end
module ClassMethods
def setting_index(arguments)
settings index: {number_of_shards: 1} do
... more code ...
end
end
我认为您需要将包含的模块放在包含的 do 块之外。