I have ruby code that calls a method to accept a candidate for a vacancy like this:
<%= link_to "Accept", accept_candidate_path(vacancy_id: @vacancy.id, employee_id: e.id), method: :post, :remote => true, :id => "link_#{i}" %>
The method changes the state in the database to Accepted.
Once that is clicked, I want to replace that with following ruby code:
<%= link_to "Cancel", back_to_pending_path(vacancy_id: @vacancy.id, employee_id: e.id), method: :post, :remote => true%>
I also have a if/else that checks the state of a candidate to display either links. But that is only triggered by refreshing the page and I just want it to accept it, change the button without completely refreshing the page.
Currently I have this:
$("[id^='link_']").click(function (event) {
$(this).replaceWith("Accepted")
});
and it works completly fine with just plain text, but I need the text to be the embedded ruby. Is this possible?
accept.js.erbfile and add the javascript here. "Unobtrusive javascript" - edgeguides.rubyonrails.org/… 3. Handle the link via AJAX in a javascript file and return a partial (via controller) with the new link. it'll take some time to type all these up with examples, but I will if you would like.