J'essayais d'ajouter un fichier CSV pour mes résultats de recherche mais il renvoie une erreur indiquant des paramètres non autorisés. Quels paramètres dois-je passer dans le lien CSV? Afin que le CSV télécharge uniquement les résultats de la recherche.
ReportsController
def revenue_search
@bookings = Booking.complete.order("created_at DESC")
date = "1-#{params['date']['month']}-#{params['date']['year']}"
date = Date.parse(date)
@bookings = @bookings.where(created_at: date.beginning_of_month..date.end_of_month)
@per_page = params[:per_page] || Booking.per_page || 20
@bookings = @bookings.paginate( :per_page => @per_page, :page => params[:page])
if params[:currency].present?
@bookings = @bookings.where(currency: params[:currency])
end
respond_to do |format|
format.html
format.csv { send_data @bookings.revenue_csv }
end
end
Model
def self.revenue_csv
attributes = %w{ total value deposit balance }
CSV.generate(headers: true) do |csv|
csv << attributes
all.each do |booking|
csv << attributes.map{ |attr| booking.send(attr) }
end
end
end
revenue.html.erb
<%= form_tag revenue_search_path, :method => 'get' do %>
<%= select_tag(:currency, options_for_select(["USD", "GBP"]), class: "form-control custom-select" , :prompt => 'By Office' ) %>
<%= select_month((@selected_date || Date.today), {}, class:"custom-select", :prompt => 'By Month')%>
<%= select_year((@selected_year || Date.today.year), {}, class:"custom-select" )%>
<%= submit_tag "Search", name: nil , class: "btn btn-info" %>
<% end %>
Total d'étudiants
Valeur des cours vendus
Total des dépôts
Paiements du solde
<%= @bookings.count %>
<%= @bookings.count %>
<%= @bookings.sum{|x| (x.payment_gross.to_f)} %>
<%= @bookings.sum{|x| (x.course&.course_fee || x.event&.course_fee).to_f - x.payment_gross.to_f }.to_f %>
Télécharger: <%= link_to "CSV", revenue_search_path(format: "csv" , params: params ) %>
logs:
ActionView::Template::Error (impossible de convertir les paramètres non autorisés en hash):
42:
43:
44:
45: Télécharger: <%= link_to "CSV", revenue_search_path(format: "csv" , params: params ) %>
app/views/reports/revenue_search.html.erb:45:in `_app_views_reports_revenue_search_html_erb___71501213_135144540'