Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this questionI'm fairly new to rails and so far it's been great but now I'm stuck. Here's what I want to do as an example:
A view displays an array of numbers from the corresponding controller. Underneath is a button. When a user clicks the button a method in the controller should be activated which sorts the array and then displays the sorted array back in the view.
What is the best way of doing something like this in rails?
Thanks in advance!
By example you can reuse the same controller action that you have used to display the original array and send an additional :sorted
parameter when the button is clicked, in the controller you return the sorted array if the param exists:
@array.sort! if params[:sorted]
Using sort!
will modify your original array object, i don't know if this is acceptable for you otherwise using sort
will return a sorted copy of your array.
Bests,
Richard
精彩评论