Where should I save standalone non-ruby scripts in my Rails app? - ruby-on-rails

This is a simple question, but I haven't been able to find an exact answer to it anywhere.
I have a standalone Python script which I am using in my Rails app. What is the appropriate folder I should save it in according to convention, so that I can push it to production (currently running it from my computer's desktop)? I think the answer is lib/assets but I want to make sure.

I don't think there is an exact answer for this question.
If it is a ruby script, it is usually placed in lib or bin.
From the rails folder descriptions in Getting Started with Rails guide:
bin/ Contains the rails script that starts your app and can contain
other scripts you use to setup, deploy or run your application.
lib/ Extended modules for your application.
You could put it in lib/assets folder as it reflects your understanding that it is an external asset used in the system.

Related

How do you configure Webpacker to work with a Rails engine?

I'm trying to configure Webpacker to work with a Rails engine. I'm specifically interested in how people are setting up their webpacker.yml to move their engine's assets to the main app's /public/ folder.
First, I've followed the Webpacker instructions for Using in Rails Engines. However, Step 7 stumps me. The idea here is to set the public_root_path to your app's /public folder. I could obviously hard-code the correct path on my personal machine, but that's unsustainable for production or other devs. I can't rely on ERB to have a dynamic path either.
I also tried the second option of Step 7 which involves middleware, but it didn't seem to have any effect.
I ultimately want to be able to import JavaScript from the engine into the main app from the app/javascript/packs/application.js file. How do I get Webpacker to find the files from the engine without hard-coding the path?

How to use capistrano v3 and shared config files with ERB

I'm converting my RoR app to use capistrano v3. I have a number of configuration file that are generated by ERB. Most of these files, like like /etc/logrotate.d/app_name, are referenced external to my app. So I like the idea of linking them to my shared/config directory. Capistrano supports managing linked files via the linked_files array. So far so good. But, the files to be linked don't technically exist until I run ERB. And capistrano runs :deploy:check:linked_files as the first step of :starting, at which point the files don't exist and the check fails.
So my question is, what's a really good way to handle this? Do I check in empty config files in my config directory, let capistrano link them to shared, and then overwrite them via ERB at a later stage? That doesn't feel good. I can't generate them before the :starting task because on an initial deploy the source tree isn't there yet. Any suggestions?

what is the use of test/dummy folder in rails?

I am starting to learn plugin development in rails, I was wondering what is the use of the test/dummy folder in the rails plugin environment. I understand that it has all the features of a regular app but what how does this help in the plugin environment. Furthermore I was unable to find good resources online for exploring the rails plugin development system, it would be helpful if good resources were posted.
The dummy app with /test works like fixture, to provide a basic environment to run the plugin's functional/integration tests.
Because this is a plugin(actually it's a gem), even it lives in /lib currently, it should have no dependency on your real app. But functional/integration tests need a Rails app, so here comes the dummy.

how to deploy a sproutcore app with rails backend using capistrano?

My project code structure is as follows:
myapp/
rails_code/
app/ models/ views/ assets/ etc
sproutcore_code/
sp/
apps/ Buildfile etc
I deploy with capistrano, and I have the rails app set up with nginx and passenger on the server, so that the server's root directory is /path/to/myapp/rails_code/public, and it works. But the rails code is the backend. I need to set up the sproutcore code as well.
So how should i set up nginx for sproutcore code in the myapp/sproutcore_code/sp directory, and how should i change the cap deploy script to build the sproutcore app?
I think what is most done that you actually move the sproutcore js to your app/assets/javascripts folder.
You should have some home-page, served by your rails-application that contains and starts the sproutcore application.
If you do it that way, you do not have to change anything to your deployment process.
I have posted a question recently asking for demo-applications with sproutcore, and found Travis-CI to be very informational for me. Not sure how you combine that with the actual sproutcore application development though.
[EDIT]: I found a good demo-project making things clearer: sproutcore-on-rails. Hope it helps you.
Since then I have looking more to spine.js, which has a direct integration with rails, and found that much easier to start with. They provide generators that builds a folder structure inside your app/assets/javascripts, and helps quick scaffolding.
Hope this helps.

Where to put Ruby scripts for script/runner on a Rails project?

I have seen examples where it is put in the lib folder, and another example in the app folder. Is there standard place where it should be put for Rails 2.3.8 and Rails 3 convention?
Scripts have to go into the /scripts folder. Of course there's almost always the confusion as to how to differentiate a script from a regular ruby file that is 'required' by a controller/model. If your script is required to start/sustain your application, then yes its a script. Or else if its a ruby file that is need at times or just for some cases wherein it complements the model/controller, you're better off putting it in the /lib folder.
I usually don't have runner scripts, but instead directly call some method that exists either on a model or in something in lib. For example, my Rails cronjobs typically look like this:
/path_to_app/scripts/runner -e production "SomeModule.perform_task"
I think this is cleaner.
I wrote a script on one one occasion, though, and in that case, I just put it in the lib directory:
/path_to_app/scripts/runner -e production /path_to_app/lib/perform_task.rb"

Resources