我的索引中有这个。但是,该命令不起作用。我可以就错误的位置得到一些反馈吗?
生成器索引
def index
@generators=Generator.order("created_at DESC")
end
结果索引
def index
@results=Result.all
end
这是日志
Started GET "/generators" for 127.0.0.1 at 2013-12-22 13:18:20 +0800
Processing by GeneratorsController#index as HTML
←[1m←[35mUser Load (2.0ms)←[0m SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]]
←[1m←[36mCACHE (0.0ms)←[0m ←[1mSELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1←[0m [["id", 1]]
←[1m←[35mGenerator Load (3.0ms)←[0m SELECT "generators".* FROM "generators" WHERE "generators"."user_id" = $1 [["user_
id", 1]]
←[1m←[36mResult Load (2.0ms)←[0m ←[1mSELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "re
sults"."id" ASC LIMIT 1←[0m [["generator_id", 10]]
←[1m←[35mResult Load (2.0ms)←[0m SELECT "results".* FROM "results" WHERE "results"."generator_id" = $1 ORDER BY "result
s"."id" ASC LIMIT 1 [["generator_id", 14]]
索引页
这是生成器索引页面。没有结果索引页
<html>
<body>
<div id="view_index">
<h2 align="center">Primer Generated Results</h2>
<p align ="center"><font size ="5"><strong>*** <u>Click Analyze for Binding-Time Analysis</u> *** </p></font></strong>
<table class="index">
<thead>
<tr>
<th class="no_col">Primer length</th>
<th class="sstring_col">Method used</th>
<th class="rpg_col">Random primer generated <b>[5'->3']</b></th>
<th class="no_col">T<sub>m</sub> (<sup>o</sup>C)</th>
<th class="string_col">Generated Time (UTC +8:00)</th>
<th class="sstring_col">Reference sequence</th>
<th class="gs_col">Description of reference sequence</th>
<th class="no_col">Binding of primer (no.of times)</th>
</tr>
</thead>
<tbody>
<% current_user.generators.each do |generator| %>
<tr class="result">
<td align="center"><%= generator.primer_length %></td>
<td align="center"><%= generator.choice %></td>
<td> <%= generator.random_primer_generated %></td>
<td align="center"><%= generator.melting_temp %><sup>o</sup>C</td>
<td> <%= generator.created_at %></td>
<% if generator.result.present? %>
<% if generator.result.ncbi_ref_seq.blank?%>
<td> NIL </td>
<td> SAMPLE </td>
<td align="center"><%= generator.result.binding_times %></td>
<%else%>
<td> <%= generator.result.ncbi_ref_seq %></td>
<td> <%= generator.result.genome_sample %></td>
<td align="center"><%= generator.result.binding_times %></td>
<%end%>
<td id="change"><%= link_to 'Details',generator_result_path(:generator_id=>generator.id, :id=>generator.result.id) %></td>
<td id="change"><%= link_to 'Delete',generator, :method => :delete, data: { confirm: 'Are you sure?' } %></td>
<% else %>
<td></td>
<td></td>
<td></td>
<td id="change"><%= link_to 'Analyze',generator_path(generator) %></td>
<td id="change"><%= link_to 'Delete',generator,:method => :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</div>
</body>
</html>
答案 0 :(得分:2)
您可以在Generator模型中设置默认范围
default_scope order('created_at DESC')
答案 1 :(得分:2)
Generator.all.order("created_at DESC")