Server side validation
In your voting model:
validates_uniqueness_of :current_user
Save your traditional controller for editing and saving.
And then using jquery use this:
$(".vote_link").submit(function(){ $.ajax({type: "POST", url: $(this).attr("action"), data: $(this).serialize(), dataType: "script", error: function(){ $("#message").show().html("You can't vote on this!")}, success: function(){ $("#message").show().html("You voted!")}; }); return false; });
And your HTML / HAML:
= link_to 'Vote on This', new_vote_path(object)
source share