Martin Chandler
2012-Mar-20 04:25 UTC
redirect_to not working as expected, sent to update instead of show
Hi,
This is my first post to this list, so apologies if anything is amiss.
After processing and AJAX PUT request to a custom method, I want to
redirect_to the show method of another controller, but redirect_to is
keeping the PUT verb, so I get sent to update instead.
Rails 3.2.2, ruby 1.9.3-p0
I have tasklists that have many tasks.
The tasks are a list, and after moving a task down in the list I want to
redirect and show the parent tasklist:
Models:
class TaskList < ActiveRecord::Base
has_many :tasks, :order => ''position asc'', :dependent
=> :destroy
end
class Task < ActiveRecord::Base
belongs_to :task_list
end
Controllers:
class TaskListsController < ApplicationController
def show
@task_list = TaskList.find(params[:id], :include => [:tasks])
end
end
class TasksController < ApplicationController
def move_task_down
@task = Task.find(params[:id])
respond_to do |format|
if @task.move_lower
format.js { redirect_to @task.task_list, :notice =>
t(''task_lists.successfully_moved'') }
else
format.js { redirect_to @task.task_list, :alert =>
t(''task_lists.error_move_task'') }
end
end
end
end
routes.rb:
resources :task_lists
put ''tasks/:id/move_down'' =>
''tasks#move_task_down'', :as =>
''move_task_down''
In the log:
Started PUT "/tasks/406137300/move_down" for 127.0.0.1 at 2012-03-20
12:19:17
Processing by TasksController#move_task_down as JS
Parameters: {"id"=>"406137300"}
......
Redirected to http://localhost:3000/task_lists/1007688486
Started PUT "/task_lists/1007688486" for 127.0.0.1 at 2012-03-20
12:19:17
Processing by TaskListsController#update as JS
Parameters: {"id"=>"1007688486"}
As seen in the log above, the user is being properly redirected to
/task_lists/xxxxxxx, but the verb is PUT instead of GET,
which routes to the update method of TaskListsController, instead of the
show method, which is where I want to go...
what am I doing wrong?
Thanks,
Martin
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/J8i-KGSAhukJ.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.