Rails 3.1:从js-file渲染/加载html片段

时间:2012-01-06 20:59:00

标签: html ruby-on-rails render

尝试将c.html.erb(与update.js.erb位于同一文件夹中)呈现为div:#wrapper2。这是代码:

index.html.erb

<div id="menuwrapper">
   <div class="tabArea">
      <%= link_to 'Lorem', {:action => 'update', :controller => 'welcome'},
      {:class=>"tab",:remote=>true} %>
   </div>
</div>
<div id="wrapper2">
   <!--Where i want to load-->
</div>

Welcome_controller:

#coding:utf-8
class WelcomeController < ApplicationController  
  def index

  end
  def update

  end
  def c

  end
end

update.js.erb :(几个不同的尝试版本)

1: $("#wrapper2").html("<%= render :partial => 'c' %>");
2: $('#wrapper2').html("<%= escape_javascript render(:file => 'c.html.erb') %>");
3: $('#wrapper2').load('c.html.erb', function() {alert('Load was performed.');});

routs.rb:

get "welcome/index"
get "welcome/update"
get 'welcome/c'

c.html.erb:

<div>
  <table>
    <tr ><td valign="top">

        <div class="maintext">
          <h1> This is some text</h1>
          <p>This is more text!</p>
        </div>
      </td>
      <td>
        <div class="slideshow"> 
          <img src="/assets/image1.jpg" width="600" height="594" /> 
          <img src="/assets/image3.jpg" width="600" height="594" />
          <img src="/assets/image2.jpg" width="600" height="594" />
        </div>
      </td>
    </tr>
  </table>
</div>

应用程序进入update.js.erb,但无法加载wrapper2。

对于如何解决此问题的任何线索表示感谢!

0 个答案:

没有答案