2012-04-15 61 views
0

我編輯的源index.html.erb頁面查看設置PARAMS:ID發佈

<% @sources.each_slice(20) do |s| %> 
    <div class="span3"> 
    <% s.each do |i| %> 
    <div><%= link_to(truncate(i.name, :length => 30) , sources_path(i.id), :class => 'action show') %></div> 
    <% end %> 
    </div> 
<% end %> 

的sources.controller是..

def index 
    @sources = Source.search(:search=>params[:search]) 

    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render json: @sources } 
    end 
    end 

問:當PARAMS [ :搜索]有效。爲什麼要顯示i.name信息並且i.id不顯示...我如何獲取i.id?

回答

0

它可能不相關的ID,它最有可能涉及到的事實,你正在使用sources_path,而不是使用SOURCE_PATH

+0

即使我將其更改爲

<%= link_to(truncate(i.name, :length => 30) , {:controller => "Sources", :action=> 'show' , :id => i.id }, :class => 'action show') %>
我仍然不會拉動i.id – RossWhit 2012-04-16 14:20:04

+0

它生成的HTML是什麼? – 2012-04-16 15:33:39