Ruby on rails - error accessing the public directory

I would like to ask you if it is possible to show the data that I have to save in / public / my _dir_for_data.

If I try to display an image from this directory, I get a "Routing Error" message. Probably when I would like to save data to the root application, for example. / my _data, everything will be fine ... but I like this structure of the RoR application, and I would be glad if I could use the directory in / Public ...

Are there any ways to do this? (and security at the same time?)

+3
source share
2 answers

If the file exists, the rails will not enter the controller stack; if it cannot find the file, it will assume that this is a dynamic action and enter the controller stack.

So, if the file exists in #{Rails.root}/public/directory/file.pngand you go to domain.com/directory/file.png, it should process the file.

Are you sure all directory and file names are the same on both sides?

+5
source

The above problem is related to the configuration settings in the config / environment / production.rb file. If you add the line below, the problem will be solved. config.serve_static_assets = true

But this line is deprecated from rails 4 and will be removed in rails 5.0. To do this, a new configuration parameter is introduced, as shown below. You will receive a warning as shown below, but static files will be downloaded.

: config.serve_static_assets config.serve_static_files, ( public ). serve_static_assets Rails 5.0. , .

, , config.serve_static_assets true, .

0

All Articles