简体   繁体   中英

Turn a button to a link with the same exact functionality

So I have this button:

<%= button_to "+1", video_votes_path( :video_id => video.id, :type => "up" ), :remote => true %>

It calls the create method in the video_votes controller, and also sets params[:type]. I want to turn this button into a link so that is does exactly the same thing. How do I do this?

button_to "+1", video_votes_path( :video_id => video.id, :type => "up" ), :remote => true
=>
link_to "+1", video_votes_path( video, :type => "up"), :remote => true, :method => :post

Change button_to to link_to_remote with an extra parameter: :method => :post , and take out the remote .

Uh, leave out the method if you want a GET.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM