On Mar 8, 5:02 pm, Shilo Ayalon <[email protected]>
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.

lib/tasks is for rake tasks. You should either remake your script to
rake task (and then execute it using Rake::Task["task_name"].invoke)
or put it to lib and then execute it by calling method from it.

> 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.

If you're using script from lib folder, then it has full access to
rails, your models and etc.

> 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.

I'd suggest somewhere outside public, maybe /reports?

> 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 viahttp://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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to