This project is archived and is in readonly mode.

#2155 new
Deleted User

Please add :position => :replace to link_to_remote (and family)

Reported by Deleted User | March 6th, 2009 @ 04:25 PM | in 3.x

link_to_remote currently supports :position => :top, :bottom, :before, :after and implicitly supports :content (the contents of the element with the tag). It seems natural to me to include :position => :replace for the times you want to replace the container element.

The current workaround is


<%= link_to_remote('text', ... %>

coupled with


    respond_to do |format|
      ...
      format.js {
        render(:update) do |page|
          page.replace 'some_dom_id', :partial => 'new_content
        end
      }
    end

and that works fine. But it means your UI code needs to be even more tightly coupled to the controller, and it hardly seems DRY.

What I'm suggesting seems cleaner and DRYer:


<%= link_to_remote('text', :position => :replace, ... %>

coupled with


    respond_to do |format|
      ...
      format.js #no code needed
    end

Comments and changes to this ticket

  • Sai Emrys

    Sai Emrys January 24th, 2010 @ 03:53 AM

    Any progress on this? I'd like it too.

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Carsten Gehling

    Carsten Gehling June 15th, 2010 @ 06:52 AM

    I think development focus is more on RJS, but I could sometimes need this too. I'll have a look and see what I can do.

    /Carsten

  • Carsten Gehling

    Carsten Gehling June 15th, 2010 @ 07:01 AM

    In the meantime, you could use :update and reference an immediate parent container.

    /Carsten

  • Carsten Gehling

    Carsten Gehling June 15th, 2010 @ 07:09 AM

    ...or you could just put your responding RJS code in a template file:

    youraction.rjs

    page.replace 'some_dom_id', :partial => 'new_conten
    

    Then you've got your view/controller separation back

    /Carsten

  • Deleted User

    Deleted User June 15th, 2010 @ 07:20 AM

    The problem with referencing the immediate parent is that you are then tightly coupling a partial to its container. It just seems totally natural to 'replace self', as it were.

    With rails3 on the horizon, I'm not sure if this makes sense in the rails3/unobtrusive world, but I still miss it in the 2.x world.

  • Carsten Gehling

    Carsten Gehling June 15th, 2010 @ 09:02 AM

    Agreed, but it was also only meant as a short-term fix - until I saw how old this ticket is :-)

    But better yet ATM is the rjs-template file to decouple controller and view code.

    I would say that even with unobtrusive JS in Rails3, this is still a valid issue. link_to_remote(:update => etc..) will still be usable. The only difference will be, that the javascript is not generated inline - instead you add some classnames and let an external JS handle the job. From a rails-programmers perspective, there will be no difference.

    /Carsten

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 1st, 2010 @ 05:08 PM

    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages