Reputation: 11
I am trying to hide this button in ruby once it is clicked so it doesn't show up again and the user thinks their request has not went through. I just want this clickable once then removed from page not just disabled
<% if @ride_request clicks %>
<%= link_to "Book Ride", :controller => "/request", :action => "book", :id => @ride.id %>
Upvotes: 0
Views: 130
Reputation: 76784
Your question is actually about JS, rather than Rails.
You have to remember Rails is a server-side framework, which means it takes a request from the front-end, and then processes a response for you. This means that any UX stuff on the front-end needs to be handled with JS
To do that, you'd be best using the $("element").remove();
function of Javascript:
$(document).on("click", "element", function(){
$(this).fadeOut(150, function() {
$(this).remove();
});
});
This will fade the button out, and then remove it from the DOM
Upvotes: 0
Reputation: 910
You can this javascript (jQuery) inside your controller specific .js file
$(document).ready(function() {
$('#replace_id').click(function (){
$(this).hide();
});
});
All you need to do now is add the id of the object and substitute it with replace_id
.
Upvotes: 1
Reputation: 406
you could try jQuery's element.hide()
http://api.jquery.com/hide/#hide
or you could toggle css' display:none
for that button
or you could try jQuery's element.remove()
http://www.w3schools.com/jquery/html_remove.asp
Upvotes: 0
Reputation: 160261
Consider using disable_with
, which IIRC works with both link_to
and submit buttons:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
Upvotes: 1