如何通过在控制器中使用单一方法将两个链接重定向到两个 url?
例子:
def index
@location_id = Location.find(@location_id)
@epc = Enr::Rds::CurrentEpc.find_by_location_id(@location_id)
if # PDF EPC link clicked
@epc.current_epc_path[-4..-1] == '.pdf'
content = open(@epc.current_epc_path, "rb") {|io| io.read }
send_data content, :filename => 'epc.pdf', :disposition => 'inline'
end
if # LIVE EPC link clicked
@epc = Enr::Rds::XmlData.find_by_location_id(@location_id)
redirect_to @epc.report_url
end
end
在我看来,
<%= link_to 'PDF', enr_location_current_epc_index_path(@location) %>
<%= link_to 'LIVE', enr_location_current_epc_index_path(@location) %>
在我的路线中
resources :current_epc, only: [:index, :show] do
get :download, :on => :collection
end