So I am creating a ruby on rails application and in my view I have a list of link_to with each being a different console
In my database table I have a field called console.
What I want to do is when a user clicks on a link e.g. Playstation 3, it will return back all records that have Playstation 3 listed in that table column.
I was wondering how I would go about doing this, I have tried searching on the internet but have not found anything similar.
It is for a project that I don’t have long to complete. I was owndering what I would state in the link to’s in the view and what I would put in the games_controller.
Any help would be much appreciated.
The basic gist is to have a controller action which will return the list of games filtering by console. For example,
Then you can create a link for any particular console as such:
link_to 'XBOX', games_path(:console => 'XBOX')This should result in a
GETrequest to the URL/games?console=XBOXIf you’ve got a pre-defined set of consoles, you might look into making them into constants inside a
Consolesmodule to avoid having to hardcode them everywhere.UPDATE:
Since you are trying to implement both searching and filtering in the same chain, you need to make sure that
find_by_consoleisn’t called if it’s not present.