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

 
3fddf42

Authority 50
Posting Rating 89
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 23
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!

 
Profile

Authority 62
Posting Rating 98
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 : nested application ApplicationController get called intead of children::ApplicationController

Ask a Rails expert : Best way to structure a database for a large/static dataset

Ask a Rails expert : Ruby Developer (ROR) - Scottish based (Remote working from within the UK)

Ask a Rails expert : Above Ground Pool Supplies

Ask a Rails expert : How to get url params in observer or model in Rails 3.1

Ask a Rails expert : What can persuade you to hire Junior Ruby devs with significant PHP experience?

Ask a Rails expert : What industry value does the Ruby or Rails Certification currently have?

Ask a Rails expert : Louis Vuitton Damier Azur Canvas specially sale ( www.salecheaplouisvuitton.com )

Ask a Rails expert : ·How to check errors/puts statements from ruby files which are under cronob

Ask a Rails expert : Louis Vuitton cheap Soft Sided Luggagespecial offer( www.salecheaplouisvuitton.com )

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