Topic: link_to_remote html option problem.

okay I had this working before I added the link_to_remote option. I had classes for each href (tag cloud) but now that I've added link_to_remote the :class option and indeed the :html option seems to not work any more.

    <% tag_cloud true, @tags, %w(nube1 nube2 nube3 nube4 nube5) do |name, css_class|  %>
        <%= link_to_remote name,
                            :url => {:action => 'show', :id => name},
                           :method => :get,
                           :class => css_class                          
                        %>
    <% end %>

the api say I can pass html options to the link_to_remote, but its not working for me.  :html => {:class => css_class} doesnt work ether.

--

Re: link_to_remote html option problem.

The format is:
link to remote name, {options },  {html options}
So you have to put all the options in { } braces and then as thrid argument, add a hash with the HTML options:

    
<% tag_cloud true, @tags, %w(nube1 nube2 nube3 nube4 nube5) do |name, css_class|  %>
  <%= link_to_remote name, #1rst parameter,
                   {:url => {:action => 'show', :id => name}, :method => :get}, #2nd parameter, options
           {:class => css_class } #3rd parameter, html options
                   %>
<% end %>

The reason this confuses many people is that when you don't need do give the 3rd parameter hash (because you don't have any html options), you can leave the { } braces for the 1st (options) hash out, as everything after the first parameter will be seen as content of the options hash. If you need the 3rd parameter, you have to mark both as hashes with {} to let ruby know where the first hash ends and the 3rd starts ...

This is a ruby thing. Can be confusing at first, but is no big deal.

Last edited by Duplex (2007-09-26 15:36:25)

Re: link_to_remote html option problem.

thanks, duplex, it did the trick

--