简体   繁体   中英

How to load a partial inside of a partial?

I'm trying to fire an AJAX request when my page loads. I'm guessing this would be best from my controller.

First I open a new page..

def text_tabs_nav
end

This page has the ability to load by AJAX two different partials. I want to load one of them on default.

So I thought maybe this ..

def text_tabs_nav
  respond_to do |format|
    format.html
    format.js
  end
end

And in my text_tabs_nav.js I wrote this :

== $("#content").html("#{ escape_javascript(render :partial => 'about_us') }");

But the javascript didn't load..I use that same javascript to load things after a page has been loaded, and it works fine.

Anyone have any idea how I could load a partial ( text_tabs_nav ), with a default AJAX partial loaded within ( about_us ) ?

Thanks!

It isn't being parsed because it's in a vanilla js file. What you want is

text_tabs_nav.js.erb

Well in a glorious blaze of defeat, I ditched the controller, an added a regular call in my view.

:javascript
  $("#content").html("#{ escape_javascript(render :partial => 'about_us') }");

Problem solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM