1

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!

Sarah
  • 516
  • 10
  • 35

1 Answers1

1

Try it without the :url hash

<%= link_to "move up", {:controller => "questions", :action => "moveup"}, :remote => true %>
rwilliams
  • 21,188
  • 6
  • 49
  • 55
  • Thanks, what ended up working was just saying <%= link_to "move up", "moveup", :remote => true %>. For some reason listing the action and controller caused a routing problem and just linking to the action name worked. Probably a routing issue on my end. I'm still not entirely sure how to do exactly what I'm looking for, since that ended up going to the url .../moveup. – Sarah Nov 16 '10 at 19:11