link_to with filter param #1517
-
On my dashboard, I would like to set up direct links to the Index / Accounts view with filters enabled (e.g. status = "check" or "block ", or due_date <= today ). I thought of creating filters but how to call them dynamically in a link_to? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
So the easiest way to do that is to go to an Index page, set the filters how you want them, and then grab the link from the URL bar. I'll explain a bit about how they work. If you're curious on seeing some code, check these files:
They are Avo's first iteration of filters, and we're working on the next improved iteration with dynamic filters. Demo below: |
Beta Was this translation helpful? Give feedback.
So the easiest way to do that is to go to an Index page, set the filters how you want them, and then grab the link from the URL bar.
That link will always take you to the same state of the filters as long as you don't change anything to that filter (like the options).
I'll explain a bit about how they work.
You first configure a filer using the
query
andoptions
methods. You add it to a resource and then you get to use it.When you use it (let's say you're toggling an option to
true
), that filter class and that value, get added to a hash alongside with all other fields you have on your resource. Then they get base64 encoded and added to thefilters
URL param. The controller then fetches t…