so I’m just trying to do something simple but I can’t seem to find any sort of solution in my books or easily googling it.
<div id="subscribe">
<% if session[:read_random]
unless is_subscribed?(session[:read_random].last)%>
<%= link_to 'Subscribe', subscriptions_path(feed_id: session[:read_random].last), method: :post, remote: :true %>
<% else %>
<%= link_to 'Unsubscribe', subscriptions_path(feed_id: session[:read_random].last), method: :delete, remote: :true %>
<% end
end %>
</div>
and my create.js.erb is:
if is_subscribed?(session[:read].last)
$('#subscribe').html("Unsubscribe");
else
$('#subscribe').html("Subscribe");
end
so I know that this code is OBVIOUSLY wrong, just please tell me what I’m doing wrong here, I would like to give the user the option to subscribe if he is not and vice versa if he is subscribed.
Do I need to put link_to inside the html portion of the jQuery statements? The only issue is, I though I would try this to see if it works, and I’m not even getting any updated text from the ajax call. Server says it has rendered subscriptions/create.js.erb and the database is being updated appropriately
solution: in views/subscriptions/create.js.erb and destroy.js.erb
alter for destroy and there you have it!