views:

22

answers:

2

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)
I have looked at the doc and it's not clear to me how to do this. I'd like to do something like the following (although I know it won't work):

link_to image_tag("button.gif"), "/home", 
        :action => 'delete_something' , 
        :confirm => 'Are you sure?',
        :method => :delete 

Thanks for any help.

+1  A: 

Well, just change the render in your controller. So, after the deletion is done just do a

redirect_to "/home"
jasonpgignac
Thanks. This does the trick. You know, I had done this originally and it had not worked, so that is how I wandered down the above path. I now wonder what I had wrong the first time. And looking at the above - am wondering if I need the ":method => :delete", I'm going to check and find out...
rtfminc
That would depend on how you built your controller. A standard resource oriented controller, for instance, would delete an object if you used method delete and the url /object/whatever_the_id_is. But if you built your controller custom, this depends on how you set up your routes file.
jasonpgignac
A: 

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.

Karl