Last active
August 29, 2015 14:08
-
-
Save sirmxanot/7a3620525ed8d4528d72 to your computer and use it in GitHub Desktop.
Rails: What is the best way to display an index with a specific list of records specified through an array of IDs?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**Background** | |
I am trying to create links that redirect to an index page listing an arbitrary set of records. I believe that the best way to accomplish this is to pass an array of the IDs of the objects that I would like to be included to the index controller method. | |
**Method** | |
I have a working solution where I look for params[:ids] in my index method and if it exists, I find those records and display them. If that params[:ids] doesn't exists, I default to the default index behavior. | |
**Problem** | |
However, since I am using GET, the array of IDs is getting included in the URI and with larger sets of IDs, I am getting the following error: | |
Request-URI Too Large | |
I think the natural way to get around this is to use POST. I can either add a post route for the index method or I can add a new POST route to a new controller method which looks up the records and then renders or redirects the results to the index action. | |
**Questions** | |
- Am I going about this in the best way? Do you know of a better way? | |
- Do you recommend using a new method that redirects to index or adding a POST route for the index? | |
- Can you point me towards a code sample where something similar is being done? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment