# Syntax with link\_to using block, remote, parameters and class/id

**URL:** <https://www.ruby-forum.com/t/syntax-with-link-to-using-block-remote-parameters-and-class-id/194729>\
**Category:** Rails\
**Created:** [September 9, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/syntax-with-link-to-using-block-remote-parameters-and-class-id/194729 "2010-09-09T16:56:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wbharding](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8797f3/32.png) [@wbharding](https://www.ruby-forum.com/u/wbharding)\
**Post date:** [September 9, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/syntax-with-link-to-using-block-remote-parameters-and-class-id/194729/1 "2010-09-09T16:56:56Z")

</div>

Rails 3rc, Ruby 1.9.2

Newish to rails; very new to rails3

I’m trying to create a link using a block so I can wrap the name  
contents in a span, for an ajax request using multiple parameters and  
finally, also specifying the class and id of the generated link element.  
Here’s what I’ve got 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 %\>  
\<%= tag %\>  
\<% end %\>

This generates the following:

[Test Descriptor](https://www.ruby-forum.com/explore/index/theme-tag-user-3?url[controller]=themes&url[action]=remove_tag&url[entity_id]=3&url[theme_id]=16&url[entity]=user&url[element_id]=filter-contributor-3&url[parent_id]=filter-contributors&remote=true&class=tag)

So, the href isn’t correct, no class or id attributes as they’re being  
treated like parameters instead, and normally with :remote=\>true, I’d  
expect to see data-remote=true in the element. Also, and this is just my  
desire to learn more about why… but a link\_to without a block would be  
something like link\_to “Link Name”, {url\_stuff…}, :remote=\>true,  
:class=“my-class”, :id=\>“1” and so on, and these all work, but why do I  
have to specify the :url=\> when using the block, but not otherwise? It  
just seems there’s a significant syntactical difference between the two  
and I don’t understand why there would be and I’d like to. Thanks.

Bill

---

<div class="post-metadata">

**Author:** ![wbharding](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8797f3/32.png) [@wbharding](https://www.ruby-forum.com/u/wbharding)\
**Post date:** [September 9, 2010, 5:29pm UTC](https://www.ruby-forum.com/t/syntax-with-link-to-using-block-remote-parameters-and-class-id/194729/2 "2010-09-09T17:29:43Z")

</div>

change :url to url\_for

---

<div class="post-metadata">

**Author:** ![wbharding](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8797f3/32.png) [@wbharding](https://www.ruby-forum.com/u/wbharding)\
**Post date:** [September 9, 2010, 5:46pm UTC](https://www.ruby-forum.com/t/syntax-with-link-to-using-block-remote-parameters-and-class-id/194729/3 "2010-09-09T17:46:43Z")

</div>

yeah, you were passing a hash and not a helper method

On Thu, Sep 9, 2010 at 11:39 AM, William K. Hatch Jr. \<

---

<div class="post-metadata">

**Author:** ![wbharding](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/8797f3/32.png) [@wbharding](https://www.ruby-forum.com/u/wbharding)\
**Post date:** [September 9, 2010, 5:41pm UTC](https://www.ruby-forum.com/t/syntax-with-link-to-using-block-remote-parameters-and-class-id/194729/4 "2010-09-09T17:41:26Z")

</div>

On Sep 9, 2010, at 11:28 AM, radhames brito wrote:

> change :url to url\_for

Thanks, that did it. Man, that was most frustrating;-)
