Note that there are some explanatory texts on larger screens.

plurals
  1. PORails date_select to generate a csv file
    primarykey
    data
    text
    <p>I'm trying to export a CSV file of Newbie user email addresses. Newbies are users "created_at" after the date selected in the date_select tag (basically the most recent sign-ups). </p> <p>I'm using the FasterCSV gem and <a href="http://synthesis.sbecker.net/articles/2007/06/07/how-to-generate-csv-files-in-rails" rel="nofollow">Scott Becker's code</a>, and borrowed the @start_date from <a href="http://snippets.dzone.com/posts/show/4630" rel="nofollow">here</a> to implement in the method.</p> <p>Here's what my controller looks like:</p> <pre><code> def newbs_export @start_date = Date.civil(params[:range][:"start_date(1i)"].to_i, params[:range][:"start_date(2i)"].to_i, params[:range][:"start_date(3i)"].to_i) @users = User.find(:all, :if =&gt; [@created_at &gt;= @start_date]) csv_string = FasterCSV.generate do |csv| # header row csv &lt;&lt; ["email"] # data rows @users.each do |user| #if user[:created_at] &gt;= Time.now csv &lt;&lt; [user.email] end end # send it to the browsah send_data csv_string, :type =&gt; 'text/csv; charset=iso-8859-1; header=present', :disposition =&gt; "attachment; filename=newbs.csv" end </code></pre> <p>Here's my newbs.html.erb:</p> <pre><code>&lt;% form_tag({:controller =&gt; "accounts", :action =&gt; "newbs_export"}, :method =&gt; "get") do %&gt; &lt;%= date_select('range', 'start_date', :order =&gt; [:month, :day, :year])%&gt; &lt;%= submit_tag("Submit") %&gt; &lt;% end %&gt; </code></pre> <p>I've mixed code and dug myself a bit of a hole trying to stitch different solutions together. Any advice on where I could go from here?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload