Wednesday 15 July 2015

ruby on rails - link making GET (rather than DELETE) request to wrong controller -


I have a link in view / question / show.html.erb that removes the tag from users <% = link_to "x" ,: Remote = & gt; True,: url = & gt; Remove_question_tag_path (@question, tag) ,: method = & gt; : Delete ,: html = & gt; {: Id = & gt; "Delete - # {tag.name.parameterize}"}%> & Lt;% end% & gt;

remove_question_tag_path The route is created by nesting tag resources inside question resources.

  Resources: questions do the resources: Answer: Members are created (Post: Vote) End Resource: Tags Member Member Deletion: End End End Ending   < P> The Rake Route shows that this route exists because I try to use it in the url  
  remove_question_tag DELETE /questions/?question_id/tags/:id/remove(.:format ) Tag #delete   

However, when I click on the link, then this tag will be replaced by the controller N controller received a request to show the action, because shows the rake routes that the destination for the route.

  received "/ question / 25? Html% 5 bid% 5D = removal & amp; method = delete and url =% 2Fuctions% 2F25% 2Ftags% 2F2% 2Fremove" For 127.0.0.1 on 2013-03-26 19:01:00 -0700   

Can you tell me what I am doing wrong?

Try this:

  <% = link_to "x ", Remove_question_tag_path (@question, tag) ,: Remote = & gt; Truth: Method = & gt; : Delete ,: html = & gt; {: Id = & gt; "Delete - # {tag.name.parameterize}"}%> Explanation: You do not specify the URL for the link, so from all the given arguments except  link_to   "x"  Creates a hash and behaves as a URL option, therefore, in the  GET  parameter instead of creating the : method  option only  DELETE  Is added.   

No comments:

Post a Comment