I am trying to create a custom link_to helper that passes sort
parameters to a link.  It has the following code, which is pretty much
just a rewrite of link_to:

  def sort_link_to(sort, old_sort, old_dir, *args, &block)
    if block_given?
      options = (args.first || {}).merge({
        :old_sort => old_sort,
        :old_dir => old_dir,
        :sort => sort
      })
      html_options = args[1]
      link_to(capture(&block),options,html_options)
    else
      name = args.first
      options = (args[1] || {}).merge({
        :old_sort => old_sort,
        :old_dir => old_dir,
        :sort => sort
      })

      html_options = args[2]

      link_to(name,options,html_options)
    end
  end

This works fine if I use it like so:

sort_link_to 'somesort','somename', :controller => 'somecontroller',
:action => 'someaction'

My question is, how do I write this in such a way that I can use named
routes, i.e., so that either of the following works?

This

sort_link_to 'somesort','somename', @someobjectwithmappedresources

or this

sort_link_to 'somesort','somename', somemappedresource_path

Currently, if I do either, it fails when it tries to merge the generated
path from the named route with the options given to the helper (which
makes sense).  If there is some method that will take a hash and convert
it to a query string that I may then concatenate to the resource path,
then that would work, but I can not find such a method.

Also, and if very, very secondary importance, is there a way to access
controller instance variables in a helper?

Thanks in advance for your time.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to