weixin_33744141 2012-11-26 21:52 采纳率: 0%
浏览 33

Rails自动加载ajax内容

I have two models:

class Phase < ActiveRecord::Base
  default_scope order('created_at DESC')

  attr_accessible :created_at, :date_due, :name, :project_id, :status

  belongs_to :project
end

class Project < ActiveRecord::Base
  attr_accessible :created_at, :name, :status, :company_id

  has_many :phases, :dependent => :destroy
end

On my project#show view, I'm using links set to :remote => true to load a single phase#show view at a time into a div.

project#show runs this to find the phases:

<% phases = Phase.where(:project_id => @project.id) %>
<% phases.each do |p| %>
  <div class="phase">
    <h3><%= link_to p.name, p, :class => "show_phase_link", :remote => true %></h3>
    <h5>Ends <%= p.date_due.strftime("%B %d, %Y") %></h5>
  </div>
<% end %>

And then some jquery loads the data into a div

$('body').delegate("a.show_phase_link", "click", function() {
  $.ajax({
    url: $(this).attr("href"),
    cache: false,
    success: function(data){
      //display phase
      $("#phase_content").html(data);
    }
  });
})

The problem is that when you get to the page, the div starts empty. I need to auto load the first phase that has status == "0", but can't seem to find how to begin to handle this one.

Thanks!!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配