How to add confirm message with link_to Ruby on rails

后端 未结 10 1691
[愿得一人]
[愿得一人] 2020-12-29 17:45

I wanted to add confirmation message on link_to function with Ruby.

= link_to \'Reset message\', :action=>\'reset\' ,:confirm=>\'Are you sure?\'
         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 18:06

    I might be mistaken but you don't specify a controller along with the :action option. Have you tried the following? Assuming you have a messages resource configured in your route:

    link_to 'Reset', message_path(@message), :confirm => 'Are you sure?'
    

    EDIT: Above is deprecated. Rails 4.0 now accepts the prompt as a data attribute. See the doc here (Thanks @Ricky).

    link_to 'Reset', message_path(@message), :data => {:confirm => 'Are you sure?'}
    

提交回复
热议问题