Adding folders to rails public folder [duplicate] - ruby-on-rails

Hello I'm new to rails.
In my RoR app folder I have a folder (app/FOLDER) that I want to make public (there are script files that need to avaliable from browser), how can I do this?

In the latest Rails the files should exist in one of the following...
app/assets
lib/assets
vendor/assets
If you cannot move the folder but still need it to be accessible you can use...
Rails.application.config.assets.paths << folder_path
Slightly more detailed answer over here...
Rails 3.1: The public directory no longer serves js assets. How to load an additional js file after page is loaded?

you shouldn't put them in app/FOLDERbut in public/FOLDER, everything going in public/ is public.
Here's an explaination of all the directories in a rails app : guides.rubyonrails.org

Related

how to have assets other than js and css files in rails

I have some object files which I want to have them in my JS codes I put them under app/assets/3d-models and when I try to get a link to it I use:
<%= asset_path("3d-models/splits2/xxx.obj") %>
But the output is /3d-models/splits2/xxx.obj which obviously the 404 NOT FOUND is the result(i.e the asset not found, the wrong link!)
Question:
How can I get an access link to a file other than common files used in rails' assets?
You can have different assets. Just place them into assets folder and link to them correctly.
Rails are using assets pipeline. This is a concept, which provides a better way to serve some static files to a website. In Rails it is implemented by Sprockets gem. Please read more here.
You can also have other static files directly in public folder and link to those files anywhere from your app. This will not be included in assets pipeline.
If you use assets_path helper method, then there is a fingerprint added to a file so the URL to the file is different then.
Please check this section.

How to preprocess files in the "public" folder in Rails?

I've got a javascript file that I need to be accessed from outside my site (from an external site), but I also want to pre-process the file (ie. with Rail's Asset pipeline) so I can make use of some environment variables in the JS File.
Any idea how to do this? If I put the JS file into the public folder, I cannot pre-process it. However, if I put the file into the assets folder structure I can pre-process it, however, it is then not public.
Please excuse my ignorance, I'm new to this! ;)
Cheers,
Matt.
What you put in your assets folder is indeed public. If it weren't you could not link to javascripts, stylesheets and images there. The only problem is that rails hashes the name of the files for cache busting purposes (only in production).
As a workaround you may create a controller action that gets the hashed file path using the javascript_url helper and redirects to it.
class ThisController < ApplicationController
def some_action
redirect_to ActionController::Base.helpers.javascript_url('javascripts/your_file')
end
end
Maybe try using grunt to build a task that exports the processed javascript file to the public folder and overwrites the old version everytime it builds.
http://developers.mobilesystem7.com/blog/post/replacing-rails-asset-pipeline-with-grunt-bower-browserify/

In Ruby on Rails, what is an "asset"?

What's considered an "asset" in the Ruby on Rails universe?
Are user generated files, such as images uploaded by the user, considered assets? Where should they be stored in the standard file structure of a Rails project? Should they be kept clear of any asset related directories like:
app/assets
lib/assets
public/assets
Relevant: The Asset Pipeline
Generally asset is anything that browser loads after it gets the HTML page. Meaning javascript, css and any images. But as you pointed out there are two different image types in a rails project.
1) the images related to your css and layout design, those go under the app/assets/images
2) the images that your users upload, those normally go into the public/system or public/uploads folder depending on what you use to receive the uploads
The lib/assets (or sometimes vendor/assets) is where you supposed to place js/css/images related to your front-end design and provided by third party libs. Say if you want to pull in some css or a js framework, that were you should place it.
And finally public/assets is where rails will compile your layout assets from the app/assets and vendor/assets folders when you run rake assets:precompile task for production.
To have it short, your design stuff goes to app/assets, and the user uploads go into public/system
User-uploaded files are not part of assets, and should definitely be kept clear of asset-related folders. You should put them somewhere in your public directory. I put mine in public/uploads, which is a common convention. And then you should ignore those files in git (or whatever VCS you're using).
Assets are basically: javascript, stylesheets, fonts, and images which are part of the site design itself, not part of the user-uploaded content.

Using ExtJS along with the Rails Assets Pipeline

For an application built on top of Rails (3.1.8) with ExtJS 4.1, we have the following files layout:
app/
assets/
javascript/
application.coffee
WID/
Lots of coffeescript files and folders.
public/
extjs/
ext-all-debug-w-comments.js and the whole ExtJS framework.
Our application heavily relies on the Ext loader (Ext.Require) to dynamically load files based on users rights / allowed modules. We would like to keep this functionality as much as possible, so only the required files are requested from the server. Bandwidth isn't really an issue, as the application is intranet-based (On a LAN).
In development environment, everything runs smooth. In production environment however, we are having problems. It looks like either the "rake assets:precompile" task is concatenating all files into an application.js file, and then when accessing our application the Ext loader complains that it can't find individual files (Because assets/WID/.../file.js isn't being served by the rails server).
So right now, i'm not sure what would be the best move to take... Is there anyone able to help us with a successful Rails + ExtJS production setup taking the best from the assets pipeline?
Thank you,
Pierre.
I think you should move your javascripts (and generally all the assets) from your public into vendor/assets/javascripts when you are in development environment. This way the asset-pipeline gets in charge.
EDIT: You may consider reverting your manifest file to application.js, not application.coffee. Generally it is a bad idea to rename these special files : application.css and application.js .In case you have some coffescript to add , just create a new file and place it in an asset directory.

Why are rails javascript assets being precompiled in development?

I have a problem with js files being compiled in development.
I have an application.js file that includes multiple other files like this:
//=require_tree .
the files in the directory are
app/assets/javascripts/user_row.coffee
app/assets/javascripts/index.coffee
Whenever I make a change to one of those files a corresponding js file gets created in the app/assets/javascripts directory, so I change user_row.coffee and I get:
app/assets/javascripts/user_row.js
This is in development mode, with the default asset configuration (I haven't changed development.rb from what the rails generator creates).
If I change the user_row.coffee file again, it gets overlooked and the already existing js file gets included by application.js.
What I don't understand are why these js files being created in the app/assets/javascript directory rather than under tmp/cache/...
Any ideas?
You should name the coffee files name.js.coffee instead of just name.coffee.
This turned out to be an issue with nodes v0.8.9. I'm using node as the javascript runtime, and after updating from v0.8.9 to v0.8.16, the problem went away.

Resources