如何在页面顶部确定指向它的URL后才能确定链接的位置。在本例中,我想将创建和编辑场景链接移动到页面的顶部,但正如您可以看到编辑场景取决于首先了解@scenario_id。放置链接在顶部
<%= will_paginate @scens, :next_label => 'Older', :prev_label => 'Newer' %>
<div class="box">
<% for scenario in @scens %>
<% @created = scenario.created_at %>
<% @updated = scenario.updated_at %>
<% @scenario_id = scenario.id %>
<% if scenario.scenario_image.exists? %>
<%= scenario_image_tag(scenario) %>
<% end %>
<%= simple_format(scenario.description) %>
<% end %>
</div>
<% if session[:role_kind] == "controller" %>
<p>
<%= button_to "Create new scenario", :action => "create" %>
<% if @scens.size > 0 %>
<%= button_to "Edit scenario", :action => "edit", :id => @scenario_id %>
<% end %>
</p>
您的代码正在循环遍历@scens,并且仅在最后一个场景中出现“编辑场景”链接。那是对的吗? – 2009-05-27 14:15:54