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