Unwanted form parameters being appended to pagination links

后端 未结 4 1092
抹茶落季
抹茶落季 2021-02-08 04:29

I have a page which is used for searching through listings by submitting data using the supplied forms. The form parameters are submitted via ajax (post request), a new record i

4条回答
  •  隐瞒了意图╮
    2021-02-08 05:19

    If someone still has problems with pagination links, there is a fix here: Kaminari: Exclude basic form params from pagination links

    Although, it does not work form me, as it was described in the commit description, there are still unwanted params in the link (:authenticity_token, :commit, :utf8, :_method), but you can exclude them by setting them to nil

    For example:

    paginate @books, params: {authenticity_token: nil, commit: nil, utf8: nil, action: nil}
    

    Result:

    2
    

    OR

    Controller:

    def index
      # here search staff, messing our params hash
      @books = Books.all
      @pagination_params = normalize_pagination_params
    end
    
    private
    def normalize_pagination_params
     params.inject({}) do |params_hash, p|
      unless p[0]=="controller"
        params_hash[p[0]] = nil
      end
      params_hash
     end
    end
    

    View:

    paginate @books, params: @pagination_params
    

提交回复
热议问题