1
我有一個控制器,它可以從URL參數(GET)獲取開始和結束日期,並獲取此時間範圍內的所有遊樂設施,並將它們輸出到我的視圖模板中。帶有Rails 5參數的link_to path(:xml)
@from = params[:from].to_date.beginning_of_day
@until = params[:until].to_date.end_of_day
@rides = current_user.rides.where(:date => @[email protected])
當我把這個呈現爲HTML沒問題。但我也希望能夠呈現爲XML,我寫了我的xml.builder模板,但有問題傳遞日期範圍參數。
現在我的link_to看起來是這樣的:
<%= link_to "Export", report_rides_path(:xml) %>
而在我的控制,我有:
respond_to do |format|
format.html
format.xml { send_data(render_to_string(:template=>"report/rides"), :type=>"text/xml",:filename => "export.xml") }
end
有什麼辦法,我可以在我的link_to發送的參數?