【发布时间】:2013-06-15 20:29:07
【问题描述】:
我将 id 从 link_to 传递到 locals。但它无法找到结果,说cannot find article without id。我需要传递 id 以在模态中显示 articles。
<% @articles.each do |a|%>
<p>
<%= link_to a.title, {"data-toggle" => "modal", "data-target" => '#myModal', :id => a.id}%>
</p>
<% end %>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria labelledby="myModalLabel" aria-hidden="true">
<%= render :partial => "site#show", :locals => {@article => Article.find(params[:id])}%>
</div>
在控制器中
def home
@articles = Article.order("created_at DESC").limit(5)
@videos = Video.order("created_at DESC").limit(5)
end
我正在从控制器获取 id。这不是零。
问题是我可以在block 中找到文章,但无法将其发送给当地人。
【问题讨论】:
标签: ruby-on-rails-3 link-to locals