Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#2155

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

Reported by Deleted User · March 6th, 2009 @ 04:25 PM

State: new
Milestone: 3.x
Assigned to: nobody
Importance: Low

Activity

  1. Sai Emrys
    Sai Emrys

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

    January 24th, 2010 @ 03:53 AM

  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  3. Carsten Gehling
    Carsten Gehling

    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

    June 15th, 2010 @ 06:52 AM

  4. Carsten Gehling
    Carsten Gehling

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

    /Carsten

    June 15th, 2010 @ 07:01 AM

  5. Carsten Gehling
    Carsten Gehling

    ...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

    June 15th, 2010 @ 07:09 AM

  6. Deleted User
    Deleted User

    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.

    June 15th, 2010 @ 07:20 AM

  7. Carsten Gehling
    Carsten Gehling

    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

    June 15th, 2010 @ 09:02 AM

  8. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 1st, 2010 @ 05:08 PM