Link that performs task and goes to different view
I am trying to perform this task:
-
-click on an image
-perform a task in current view/controller (ie NOT in /home)
-end up on a different page (view, in this case /home)
link_to image_tag("button.gif"), "/home",
:action =>开发者_高级运维 'delete_something' ,
:confirm => 'Are you sure?',
:method => :delete
Thanks for any help.
Well, just change the render in your controller. So, after the deletion is done just do a
redirect_to "/home"
Is this what you're looking for?
# some_controller.rb
def delete_image
find_and_delete_image
redirect_to :action => :home
end
def home
show_stuff
end
You will have to pass some sort of information along with your image to identiy it, probably via URL params or POST params, but I don't really want to get into that.
I would recommend looking into RESTful routes, like the ones generated by scaffolds, it's cleaner and generates a lot of the routes for you.
精彩评论