Justin Meltzer
Justin Meltzer

Reputation: 13548

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?

Upvotes: 0

Views: 550

Answers (2)

fl00r
fl00r

Reputation: 83680

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

Upvotes: 1

Satya
Satya

Reputation: 4478

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.

Upvotes: 0

Related Questions