我試圖通過我的控制器獲取值,並且它在我的日誌中正確打印。但是,當我在我的視圖中打印時發生錯誤。Ruby on Rails - 值在日誌中正確打印但未在視圖中
控制器:
@leads = Lead.all.order('updated_at desc')
@leads.each do |k|
if k.lead_propertiesproperty_id = k.lead_properties.map(&:property_id)
properties = Property.where(:id => property_id)
category_ids = properties.map(&:property_category_id)
categories = PropertyCategory.where(:id => category_ids)
@category_names = categories.map(&:name).exists?
Rails.logger.debug("categories: #{categories.inspect}")
Rails.logger.debug("category_names: #{@category_names.inspect}")
else
@properties = "No Properties"
@locations = "No Locations"
end
end
@leads_total = Lead.all.count
查看:
<tbody>
<% @leads.each do |lead| %>
<tr class="<%=cycle('odd', 'even') %> location_row" id="lead_row" data-id="<%= lead.id%>">
<td><%= lead.id %></td>
<td><%= lead.fullname %></td>
<td><%= lead.email %></td>
<td><%= lead.phone %></td>
<td><%= @category_names.to_sentence %></td>
<td><%= select_tag :status, options_for_select(Lead.statuses.keys.to_a{|k, v| [k.humanize.capitalize, v]}, lead.status), :class => "lead_status"%></td>
<td><%= lead.created_at.strftime("%d %b. %Y - %T")%></td>
<td><%= link_to (fa_icon "pencil-square-o "), edit_lead_path({:id => lead.id, :first_last_name => lead.first_last_name}), :title => 'Edit Lead', :class => "action-button" %></td>
</tr>
<% end %>
</tbody>
錯誤: 在控制器記錄它提供了正確的類別(如桌子,虛擬化,私有)每個潛在客戶的價值,但在視圖中,它爲每個潛在客戶提供最後一個潛在客戶的分類價值。
什麼是錯誤? –
沒有錯誤,它只是給出了第一個潛在客戶屬性類別的值。 「虛擬」..相反,它應該給出它所關注的行的類別。我會在問題中添加更新。 –
很難看到錯誤在哪裏。試着描述你想要什麼以及你在答案中實際得到了什麼。也許可以在代碼中添加註釋以顯示它在做什麼。 –