Cameron Bass Cameron Bass - 1 year ago 107
Ajax Question

Rails Form helpers - Input - Ajax

I have a this form.

<%= form_for @snitch, html: { class: "form-actions", method: 'delete' } do |form| %>
<span class="button-text"><%= link_to 'NO WAY!', home_base_url_or_default(root_path), rel: "modal:close" %></span>
<input type="submit" class="button button--modal delete-snitch" data-snitch-id="<% @snitch.token %>" value="Yes, delete it.">
<% end %>

As you can see on the 3rd line there is an input type. I have this attribute on it
I have it set to the snitch token. I'm just wondering if that is correct because its coming back as undefined...

Here is how I know.

I'm using it for a Ajax call

$(document).on('click','.delete-snitch', function(e) {
var snitchID = $(this).attr('data-snitch-id');
type: 'DELETE',
url: '/snitches/' + snitchID,
datatype: 'json'
success: function(){
$('#tr-for-snitch-' + snitchID).fadeOut

But it's not working because the
comes back as undefined.

Answer Source

You have to use <%= @snitch.token %> instead of <% @snitch.token %> to output that value.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download