当我尝试转到下一页时,它会重定向到第一页。添加排序和搜索后出现此问题。也许路线有问题。
BoardController
class BoardController < ApplicationController
def index
if params[:set_locale]
redirect_to board_url(locale: params[:set_locale])
else
@search = Ad.published.search(params[:q])
@ads = @search.result.page(params[:page])
@search.build_condition
@search.build_sort if @search.sorts.empty?
end
end
def search
index
render :index
end
end
Board Index.html.slim
= search_form_for @search, url: search_ads_path, method: :post do |f|
= f.condition_fields do |c|
= render "condition_fields", f: c
.field
= t('.sort')
= f.sort_fields do |s|
= s.sort_select
.actions
= f.submit t('.look_for')
...
= paginate @ads
_condition_fileds
.field
= f.attribute_fields do |a|
= a.attribute_select associations: [:category]
= f.predicate_select
= f.value_fields do |v|
= v.text_field :value
= link_to t('.remove'), '#', class: "remove_fields"
路线
Rails.application.routes.draw do
resources :users
get 'home/index'
get 'board/index'
scope '(:locale)' do
resources :images
devise_for :users
resources :categories
resources :ads do
collection do
get 'search'
end
collection { post :search, to: 'board#index' }
end
root to: 'board#index', as: 'board', via: :all
end
end