0

I am trying to implement a system where in order to keep track of a projects progress, you can tag it with various versions (like the tagging feature on Stack Overflow. I am following along with Rails 3 book in action project, Ticketee.) I am trying to implement a asynchronous request to delete a tag from a ticket, but for some reason it's not deleting properly. Here is my code:

routes.html.erb

resources :tickets do
  resources :comments
  resources :tags do
    member do
      delete :remove
    end
  end
end

tags_controller.rb

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
  render :nothing => true
end
end

views/tags/remove.js.erb

$('#tag-<%= @tag.name.parameterize %>').remove();

views/tags/_tag.html.erb

<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>

When I click the "x" link it refreshes the page, but doesn't actually remove it. Any idea why? I have posted the code that I think is relevant... let me know if you need more.

0

1 Answer 1

1

Do you have rails_ujs included ? rails_ujs is the one which does the cool stuff like link_to with remote. btw, its

= link_to "x", url, :remote => true"

See http://guides.rubyonrails.org/getting_started.html#listing-all-posts

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I changed it to that syntax. How do I go about including rails_ujs?
I have //= require jquery_ujs in my javascripts/application.js file
The = link_to "x", url, :remote => true" syntax fixed it. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.