On 8 Mar 2009, at 15:02, Shilo Ayalon wrote:
> > Hi - > > I want to enable the user to generate a report based on the database > used by the application. I have a few related questions: > > 1. Assuming my script is called 'create_report.rb' and stored under > /lib/tasks, how do I execute it from my controller once the user > clicked > the link? I read that 'send_file' is probably what I want. > > 2. ActiveRecord is great (statement), and I want to use it in this > script. Do I need to require 'activerecord' or anything in the actual > file? I would like to use AR much like I do in my views (@users = > User.find(:all), user.full_name, etc.) - Does it just work or do I > need > to somehow load the existing models to memory. > So either you create a file somewhere on disk and use send_file (or one of the speedier alternatives) (the file doesn't have to be in / public, bear in mind that anyone can get files from there) or you create the data in ram and use send_data. If your report generation is a standalone process then you have to worry about setting up the right environment, but you may not need to do that - you could call the report code directly from your app (or to put things another way 'report code' is just the same as normal code). Fred > 3. where is the logical place on the server to store files I create > (if > there is one)? I was thinking /public/files/ or something, or even > outside my application root. > > 3. for the sake of example, I want to return a csv file containing all > users and their birthdays: http://pastie.org/410902 > > It's very incomplete, but I'm hoping someone can point me in the right > direction... thanks. > -- > Posted via http://www.ruby-forum.com/. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---