In my Rails 3 app, I have a list of questions. Each question has a "question number" which designates its order in the table/list. I'm trying to implement a "Move Up" link that will decrement that question's number to move it up in the list (1 is at the top), and increment the number of the question that previously had that number.
I'm stuck on how to call the rails function, either in the controller or model, from the question table view. Ideally I want to do something like:
<%= link_to 'Move Up', Question.moveup(question.id),
:remote => true, :update => "questions_table" %>
But that doesn't seem to be possible with any combination of "onclick", "remote_function", etc that I've looked into.
I've also tried to call the function in the controller by URL, like this:
<%= link_to "move up", :url => {:controller => "questions", :action => "moveup"}, :remote => true %>开发者_开发知识库
but it keeps searching for the url by appending edit?url[controller]=questions&url[action]=moveup which I do not want. Is there a straightforward way to call a function in a rails 3 model or controller from a link, remotely?
Thanks so much!
Try it without the :url
hash
<%= link_to "move up", {:controller => "questions", :action => "moveup"}, :remote => true %>
精彩评论