Syntax for link_to with a block in rails3 with: remote => true and including: class and: id

For love of God, I banged my head about this for several hours. Using rails3 rc, 1.9.2.

I am trying to create a link_to that sends an ajax request with parameters, class and id and needs a block, so I can insert a span tag around the name. The documentation is absolutely zero, as are numerous search queries. Here is what I have so far:

<%= link_to(
      :url=>{
        :controller => 'themes', :action => 'remove_tag',
        :entity_id => entity_id, :theme_id => theme_id,
        :entity => entity, :element_id => element_id, :parent_id=>parent_id
      },
      :remote => true,
      :id => "theme-tag-#{entity}-#{entity_id}",
      :class => "tag")  do %>
  <span class='subtract'><%= tag %></span>
<% end %>

The generated URL is as follows:

<a href="/explore/index/theme-tag-user-3?url[controller]=themes&amp;url[action]=remove_tag&amp;url[entity_id]=3&amp;url[theme_id]=16&amp;url[entity]=user&amp;url[element_id]=filter-contributor-3&amp;url[parent_id]=filter-contributors&amp;remote=true&amp;class=tag">

Test descriptor  

I cannot correctly indicate that the text "test descriptor" is actually correctly included in the range; formatting the code here doesn’t work a bit, however href is wrong, there is no class or id, and it continues to roll downhill

, : url = > {...} ( , ), : remote = > true,: id = > "whatever",: class= > "blah", . ? , , ? , , -...; -)

+3
2

, url_for (...) : url = > {...}, , .

+3

wkhatch , .

<%= link_to(
    url_for(:controller=>'themes', 
            :action=>'remove_tag', 
            :entity_id=>entity_id, 
            :theme_id=>theme_id, 
            :entity=>entity, 
            :element_id=>element_id, 
            :parent_id=>parent_id), 
    :remote=>true, 
    :id=>"theme-tag-#{entity}-#{entity_id}") do %>
       <span class='subtract'></span><%= tag %>
<% end %>
+2

Source: https://habr.com/ru/post/1763938/


All Articles