Ruby on rails Rails 3:sunspot solr:为每个页面添加搜索功能
如何将搜索添加到版面中,使其可以在网站的每个页面中搜索帖子?比如这里的stackoverflow 教程将向PostsController的索引操作添加搜索方法,然后在views/post/index.html.erb中添加表单和结果块 我一直在尝试在application.html.erb中创建一个表单,向posts控制器的搜索操作发送get请求。我似乎不太对劲,有人能帮我解释一下我哪里做错了吗 当前,我在访问主页时遇到以下错误: 主页中的名称错误 未定义的局部变量或方法“搜索路径” 后置控制器 后模型 routes.rb 视图/布局/application.html.erbRuby on rails Rails 3:sunspot solr:为每个页面添加搜索功能,ruby-on-rails,ruby-on-rails-3,search,solr,sunspot,Ruby On Rails,Ruby On Rails 3,Search,Solr,Sunspot,如何将搜索添加到版面中,使其可以在网站的每个页面中搜索帖子?比如这里的stackoverflow 教程将向PostsController的索引操作添加搜索方法,然后在views/post/index.html.erb中添加表单和结果块 我一直在尝试在application.html.erb中创建一个表单,向posts控制器的搜索操作发送get请求。我似乎不太对劲,有人能帮我解释一下我哪里做错了吗 当前,我在访问主页时遇到以下错误: 主页中的名称错误 未定义的局部变量或方法“搜索路径” 后置控制器
这是一个RubyonRails路由问题
成员
路由用于对单个记录进行操作。因此,您正在定义search\u post\u路径(@post)
,它将路由到类似/posts/1/search
您需要的是收集
路线
resources :posts do
member do
get :likers
end
collection do
get :search
end
end
这将创建search\u posts\u路径
方法,并按照您的预期路由到/posts/search
另请参见:我正在尝试确切的步骤,但出现以下错误:“找不到id=search的帖子”。任何帮助都将不胜感激。ThanksArko,
集合
没有正确注册,Rails默认为对:posts
资源执行show
操作。继续尝试:)
searchable do
text :title, :default_boost => 2
text :content
end
match 'auth/:provider/callback' => 'authentications#create'
resources :authentications
devise_for :users, :controllers => {:registrations => 'registrations'}
resources :posts do
member do
get :likers, :search
end
end
resources :relationships, :only => [:create, :destroy]
resources :appreciations, :only => [:create, :destroy]
root :to => "pages#home"
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/blog', :to => 'pages#blog'
resources :users do
member do
get :following, :followers, :likes
end
resources :collections
end
<%= form_tag search_posts_path, :method => :get do %>
<p>
<%= text_field_tag :q, params[:q] %> <%= submit_tag "Search!" %>
</p>
<% end %>
def home
@title = "Home"
if user_signed_in?
@user = current_user
@post = current_user.posts.build
@feed_items = current_user.feed.paginate(:per_page => "10", :page => params[:page])
else
#render :layout => 'special_layout'
end
end
resources :posts do
member do
get :likers
end
collection do
get :search
end
end