开发者

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)

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜