Frederick Cheung wrote:
> On May 4, 3:35�pm, "Mike P." <[email protected]> wrote:
> 
>> Thanks for your response. The other parts of the app (i.e. the
>> controllers) do seem to pick up this model. The class in the /lib folder
>> is being used separately. I'm currently running it manually, but I'm
>> looking into running it automatically using �a cron job or something
>> similar later on.
>>
>> So, it's not included by another file at the moment, as it's meant to
>> run as a standalone script. (I'm guessing that may have fixed the
>> problem if that file already had access to the model.)
> 
> What does running it manually mean - is the rails environment loaded ?
> If it isn't then you have your answer (since one of the things that
> gets you is rails' magic file loader)
> 
> Fred

Ah! That was the problem, thank you! I've been running it using:

$ ruby app/lib/class_a.rb

(The file has a call to "run()" outside of the class methods, which 
calls ClassA::run.)

But by running the script using the line below, the Rails environment is 
loaded properly and the script works fine. :)

$ script/runner app/lib/class_a.rb

I'm still kinda new to Rails, so I didn't know that I'd need to do that, 
but it makes total sense!

> Shouldn't it be in
> 
> {Rails.root}/lib/class_a.rb
> 
> rather than
> 
> {Rails.root}/app/lib/class_a.rb
> 
> ????
> 
> --
> Rick DeNatale

By '{Rails.root}', do you mean the app's root directory, or the Rails 
root directory?

Anyway, I put it in {AppRoot}/app/lib because, for some reason, I 
thought that the {AppRoot}/lib folder was for external libraries (i.e. 
the ones I didn't write). I like it this way anyway because things are 
separated better, in my opinion. I know that the stuff in the /app 
directory are the things that I made, and I don't really need to visit 
the {AppRoot}/lib folder unless there's something in there that I want 
to modify.

Or is this against Rails' best practices?

Thanks again,
Mike

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