1

我正在尝试创建一个链接列表,其中包含链接中的供应商名称,并使用该供应商名称导出数据。我知道我现在在模型中输入的内容是错误的,我只是不确定如何正确传递供应商.. 抱歉,如果这含糊不清,这是我到目前为止的代码:

控制器

def export_supplier    
@software = Software.find_supplier
software = CSV.generate do |csv|

# for the headers of the csv file
  csv << ["Quantity", "Item Number", "Item Description"]
  # the chosen rows from the database
  @software.each do |s|
    csv << [s.amount, s.productcode, s.description]
  end
end
send_data(software, :type => 'text/csv', :filename => 'software.csv')
end

看法

<% @softwares.each do |l| %>
<li>
    <%= link_to "#{l.supplier}", :controller =>'softwares', :action => 'export_supplier'%>
</li>
<% end %>

模型

def self.find_supplier
find_by_sql("SELECT s.productcode, s.description, CAST(SUM(l.amount) as UNSIGNED) AS amount
FROM softwares s
LEFT JOIN licenses l ON s.id=l.software_id
WHERE s.supplier = #{l.supplier} AND l.amount > 0
GROUP BY s.supplier, s.vendor, s.title, s.edition")
end
4

1 回答 1

0

<%= link_to "#{l.supplier}", :controller =>'softwares', :action => 'export_supplier',:supplierid=>l.supplier.id%>或者

如果路由是成员路由

<%= link_to "#{l.supplier}", export_supplier_software_path(software,:supplier_id=>l.supplier.id%>)

如果路线是收集路线

<%= link_to "#{l.supplier}", export_supplier_softwares_path(:supplier_id=>l.supplier.id%>)

于 2012-10-03T12:57:29.137 回答