I have a case on url that generated by kaminari paginate
as the url depends on a condition. Here is my routes
concern :search do
scope '/search', as: :search do
get '/', to: 'users#search'
get '/schedule/:id', to: 'schedules#doctor', as: :schedule
end
end
concerns :search
scope :dashboard, as: :dashboard do
concerns :search
end
As you can see, the :search
is accessible through /search
and /dashboard/search
. The problem is, paginate @doctors
gives /search
which basically will goes to search_path
even though I'm on dashboard_search_path
(it should gives /dashboard/search
path).
My question is, how can I pass a custom path to paginate
? I'd like paginate
to use search_path
when I open /search
and use dashboard_search_path
when I'm on /dashboard/search/path
.
You don't have to provide how to decide /search
or /dashboard/search
, I just need to know how to pass it to paginate
as an argument. Ta
Kaminari accepts parameters for paginate, one of them is params
for the links. It works the same as url_for
in rails. Didn't test it, but try for dashboard pages, should work.
paginate @doctors, params: { script_name: "/dashboard" }
From docs for url_for
:
:script_name - specifies application path relative to domain root. If provided, prepends application path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With