I am starting to learn Rails and I am facing an issue which I suppose is very simple but I have not been able to find an answer.
I have a catalog of movies and the index page displays it showing several columns and I need to make two of them a link. This link will re-display the index page again but sorted by the selected criteria.
So far I have only added one link as follows:
%th= link_to 'Movie Title', root_path
But I am not able to send a URL parameter so I can get it in the controller and perform the sort. The actual controller is as follows:
def index
@movies = Movie.all
end
I guess that, if I can get a parameter in the controller then using an "if" statement would do the job. I imagine an URL like this, where "1" means to sort by the first criteria:
http://www.mysite/1
I saw a solution like this but I guess it is not a good choice. Please advice.
<%= link_to "Link Title", something__path(:param1 => "value1", :param2 => "value2") %>
I will very much appreciate any suggestions on how to modify the view and the controller. I have googled several solutions but I am having a hard time understanding the solutions. Maybe there is a better approach to achieve this. If so, then I am ready to listen.
Respectfully,
Jorge Maldonado