Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert Rendering a template with rend...

Replytotopic

Rendering a template with render :update?

Posted in Forums : Ask a Rails expert

 
Me

Authority 50
Posting Rating 100
Sign in to rate this post

Hi there,

I’m currently working on a page that relies heavily on AJAX. Apart from the main area, most content opens up in one popup window (a div), i.e. the same div is used for all contents.
As a result, it would be best if controllers could just replace the content of the div with the full contents of a template like this:

respond_to do |format|
  format.js do
    render :update do |page|
      page[:popup].replace_html :template => "customers/index.html.erb" 
    end
  end
end

The reason I don’t want to put this in a partial is that I use the same templates as a fallback for users that have javascript disabled.

Unfortunately, this doesn’t seem to work because Rails doesn’t recognize the :template option with :update. As soon as I replace it with a :partial option, everything works smoothly. Before trying this approach, I had link_to_remote with an :update option, but I don’t like this for various reasons – mostly, because it bloats my controllers with conditionals.

Does anyone have a suggestion what I should do? I’m open to code changes, too, if you think that helps.

Cheers,
- Clemens

 
Profile

Authority 37
Posting Rating 78
Sign in to rate this post

I believe one way is to put that code into a partial, then create the template that uses the partial

_index.html.erb
  <div>my partial code here</div>

index.html.erb
  <%= render :partial => 'index' %>

 
Me

Authority 50
Posting Rating 100
Sign in to rate this post

Yes, Jeff, this is exactly how I worked around this problem. It looks kind of sucky, but well, it works …

Thanks anyway.

Replytotopic

Other Recent Topics

Ask a Rails expert : How to convert time in mililsecond

Ask a Rails expert : "redirect_to" in lib

Ask a Rails expert : weekly logins

Ask a Rails expert : how to use hpricot in views

Ask a Rails expert : link_to image_tag problem

Ask a Rails expert : Gem Insatllation Error

Ask a Rails expert : Passing an Object via selection list

Ask a Rails expert : How to create array from xml data

Ask a Rails expert : How to Call Controller from another

Ask a Rails expert : Using Antwrap in Ruby

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel