Skip to content

Instantly share code, notes, and snippets.

@eguneys
Created November 18, 2014 18:18
Show Gist options
  • Save eguneys/dd6f355b35045074fa38 to your computer and use it in GitHub Desktop.
Save eguneys/dd6f355b35045074fa38 to your computer and use it in GitHub Desktop.

This is tags controller with a remove action, it is supposed to render remove.js.erb.

class TagsController < ApplicationController
  def remove
    @ticket = Ticket.find(params[:ticket_id])
    if can?(:tag, @ticket.project) || current_user.admin?
      @tag = Tag.find(params[:id])
      @ticket.tags -= [@tag]
      @ticket.save
    end
  end
end

This is the link that triggers the action, it is supposed to be asyncronous request to this action so it renders javascript instead of html.

<span class="tag" id="tag-<%= tag.name.parameterize %>">
  <% if can?(:tag, @ticket.project) || current_user.admin? %>
    <%= link_to "x",
    :remote => true,
    :url => remove_ticket_tag_path(@ticket, tag),
    :method => :delete,
    :html => { :id => "delete-#{tag.name.parameterize}" } %>
  <% end %>
  <%= tag.name %>
</span>

The problem is the remove action doesn't render remove.js.erb instead it returns an html page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment