This is how i fixed it
I put this into a separate file called _action.html.erb
<% if Excont.where(:user_id=> current_user,:movie_id => @movie.id,:actionall => '2').includes(:user).all.count == 0%>
<tr style="border-top: none; ">
<td>
<%= link_to('Mark as action', {:controller => :excont, :action => 'thisisanaction', :id=> @movie.id, :actionall=>'2'}, :method => :post, :remote => true, :disable_with => 'Updating...') %>
</td>
</tr>
<% else %>
<tr style="border-top: none;">
<td>
<%= link_to('Unmark as action', {:controller => :excont, :action => 'removethisisanaction', :id=> @movie.id, :actionall=>'2'}, :method => :post, :remote => true, :disable_with => 'Updating...') %>
</td>
</tr>
<% end %>
I then created two .js.erb
files named after both of the action (which is very important i've found), so thisisanaction.js.erb
and removethisisanaction.js.erb
.
These two files have to be both placed in the folder of the appropriate controller, in this case excont
, if not it wont work.
Both of these folders should contain this code
$(".excontaction").html("<%= escape_javascript(render('layouts/action'))%>");
In the view where you want the button to show you add this
<div class="excontaction">
<%= render 'layouts/action' %>
</div>
The div class
or id
should match the one you put in the .js.erb
folders
This should work!