# Is it possible to use link\_to\_remote with dynamic links?

**URL:** <https://www.ruby-forum.com/t/is-it-possible-to-use-link-to-remote-with-dynamic-links/108821>\
**Category:** Rails\
**Created:** [July 7, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-use-link-to-remote-with-dynamic-links/108821 "2007-07-07T17:39:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjsquire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@rjsquire](https://www.ruby-forum.com/u/rjsquire)\
**Post date:** [July 7, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-use-link-to-remote-with-dynamic-links/108821/1 "2007-07-07T17:39:54Z")

</div>

As part of a search results page, I’m trying allow users of a particular  
application to view more details of individual products without 1)  
having to load a whole new page, 2) loading details through an IFRAME or  
3) having to preload all of the product data into the results page.

Ajax seemed to be an appropriate approach, so I created a blank layer  
called “product\_details” which is hidden by default and setup the  
following code:

 \<% @products.in\_groups\_of(8, false) do |row\_products| %\> \<% for product in row\_products%\> \<% end %\>

| \<%= link\_to\_remote( image\_tag('/images/sample.jpg'), :url =\> { :controller =\> 'store', :action =\> 'results' }, :update =\> "product\_details", :complete =\> "new Effect.Appear('animation', { duration: 3.0 })" ) %\>

```
     </td>
     <% end %>

```

 |

1. How could I pass an individual product variable through this link -  
if at all - to the controller?

2. How can I use a variable in the link\_to\_remote tag? Specifically, the  
image will always be the ID of the product, but I can’t just insert  
product.id into the code.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![rjsquire](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/74df32/32.png) [@rjsquire](https://www.ruby-forum.com/u/rjsquire)\
**Post date:** [July 8, 2007, 10:06am UTC](https://www.ruby-forum.com/t/is-it-possible-to-use-link-to-remote-with-dynamic-links/108821/2 "2007-07-08T10:06:37Z")

</div>

> ```
> <%= link_to_remote( image_tag('/images/sample.jpg'),
> :url => { :controller => 'store', :action => 'results' },
> :update => "product_details",
> :complete => "new Effect.Appear('animation', { duration: 3.0 })" )
> 
> ```

> 1. How could I pass an individual product variable through this link -  
> if at all - to the controller?

…if you mean you want to pass a product object to the controller, u  
pass the object id to the controller, and find it, ie:

:url =\> { :controller =\> ‘store’, :action =\> ‘results’, :prod\_id =\>  
product.id },

> 1. How can I use a variable in the link\_to\_remote tag? Specifically, the  
> image will always be the ID of the product, but I can’t just insert  
> product.id into the code.

if you have an image per product, and want to display it use the “#{}”  
ruby string#eval thing

```
 <%= link_to_remote( 

```

image\_tag("/images\_path/prod\_#{product.id}.jpg"),

(i feel like i’m missing something in your request, but the above is the  
simplest thing that comes to my mind)

hth
