在 comfortable_mexican_matress 中扩展模型
extending model in comfortable_mexican_matress
我正在尝试在我的 rails 应用程序中实现全文搜索。该应用程序基于 comfortable_mexican_sofa. For the full-text I am using the sunspot gem。我需要将可搜索属性添加到页面 class。我在具有相同 class 的模型下创建了一个新文件,但它似乎不起作用。我该如何扩展这个 class?我收到错误
`undefined method `search' for #<Class:0x007fbe90f6faa8>`
app/models/Page.rb
class Comfy::Cms::Page < ActiveRecord::Base
searchable do
text :label, :content_cache
boolean :featured
end
end
articles_controller.rb
def index
since = params[:sinceDate]
query = params[:searchQuery]
@articles = nil
if query
@articles = Comfy::Cms::Page.search{ fulltext query }.published.all
else
@articles = Comfy::Cms::Page.published.all
end
if since
@articles = @articles.reject{ |a| a[:created_at] < Date.parse(since) }
end
# @articles
# if query
# @articles = @articles.select{ |a| a[:label].match(/#{query}/i) }
# end
end
您可以尝试这样做:
制作一个文件并将其放入您的初始化程序文件夹中:
Comfy::Cms::Page.class_eval do
searchable do
text :label, :content_cache
boolean :featured
end
end
我正在尝试在我的 rails 应用程序中实现全文搜索。该应用程序基于 comfortable_mexican_sofa. For the full-text I am using the sunspot gem。我需要将可搜索属性添加到页面 class。我在具有相同 class 的模型下创建了一个新文件,但它似乎不起作用。我该如何扩展这个 class?我收到错误
`undefined method `search' for #<Class:0x007fbe90f6faa8>`
app/models/Page.rb
class Comfy::Cms::Page < ActiveRecord::Base
searchable do
text :label, :content_cache
boolean :featured
end
end
articles_controller.rb
def index
since = params[:sinceDate]
query = params[:searchQuery]
@articles = nil
if query
@articles = Comfy::Cms::Page.search{ fulltext query }.published.all
else
@articles = Comfy::Cms::Page.published.all
end
if since
@articles = @articles.reject{ |a| a[:created_at] < Date.parse(since) }
end
# @articles
# if query
# @articles = @articles.select{ |a| a[:label].match(/#{query}/i) }
# end
end
您可以尝试这样做:
制作一个文件并将其放入您的初始化程序文件夹中:
Comfy::Cms::Page.class_eval do
searchable do
text :label, :content_cache
boolean :featured
end
end