Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert RJS partial rendering...

Replytotopic

RJS partial rendering

Posted in Forums : Ask a Rails expert

 
244399796_d8179fee19_t

Authority 0
Posting Rating 18
Sign in to rate this post

I’m having a problem with the RJS Partial rendering.

Scenerio:

Ajax link generator

<%= link_to_remote "ProductSets", :url => "/categories/1/product_sets", :method => :get %>

and the generated html/js is
<a onclick="new Ajax.Request('/categories/1/product_sets', {asynchronous:true, evalScripts:true, 
method:'get', parameters:'authenticity_token=' +
 encodeURIComponent('164e6c54bbb20a0b544e80ad8aa694bfa65cafeb')}); 
return false;" href="#">ProductSets</a>

Since the request hits /categories/1/product_sets via method :get, the index action is invoked.
The content of the index.js.rjs template is

page.replace_html :contentTop, :partial => 'list_product_sets', :collection => @product_sets

When I click the ProductSets link, the div with ID contentTop is replaced with the response from the server. But the response is all javascripts.

try {
Element.update("contentTop", "\u003Cdiv class=\"innerConte .. .... 

All the html contents of the partial _list_product_sets.html.erb is returned with encoded javascript codes.
Can Anyone plz explaing me Whats wrong with the above code??
Thanks

 
Image

Authority 50
Posting Rating 90
Sign in to rate this post

Its seems to do right job, but incorrectly..
try:
<%= link_to_remote “ProductSets”, :url => ”/categories/1/product_sets”, :method => :get, :update =>”contentTop” %>
and then replace index.js.rjs to index.erb.rhtml with <%= render :partial => ‘list_product_sets’ %>
..

 
244399796_d8179fee19_t

Authority 0
Posting Rating 18
Sign in to rate this post

@Alexey,
Now it works!
But can you plz tell me what was the problem? Knowing it gonna clear me and others newbie out there.
Thanks for you help!

 
N780245106_2740

Authority 50
Posting Rating 76
Sign in to rate this post

Are you sure you havent used the :update otion for link_to_remote ? The server response is okay, but what is done with it by the browser indicates that the JS returned by the server is used by Element.update instead of evaluated…

Anyway, if you’ve chosen to go Alexey’s way then perhaps this would be even better:

In your controller:


def index
  @product_sets = #...
  respond_to do |format|
    format.js { render :partial => 'list_product_sets', :collection => @product_sets }
  end
end

Now you can get rid of the index.html.erb or index.rhtml file which only contained 1 line of code anyway…

Replytotopic

Other Recent Topics

Ask a Rails expert : Send dynamicly generated pdf as attachement

Ask a Rails expert : Rails Google Maps Plugin

Ask a Rails expert : link_to_remote to empty a field

Ask a Rails expert : calling class method in before filter

Ask a Rails expert : Storing values in database from popupwindow form

Ask a Rails expert : Optimising code

Ask a Rails expert : File upload

Ask a Rails expert : Deployment Question

Ask a Rails expert : Prevent session dumps from search robots

Ask a Rails expert : Best way to protect contact form

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