When using PHP, any file manipulation is done relative to the server root, so something like mkdir("/home/website/public_html/a_directory would be used to create a directory in the public_html folder where the script is executed from.
In Rails, using the FileUtils module, it is relative to the Application's path like FileUtils.mkdir('public/a_directory') which will create a folder in the public folder of the application.
The problem I face is that from my Application, I would like to be able to create directories, move files, rename files/folders and remove file/folders relative to the server's root.
What's the best way to achieve this? OR am I missing something obvious?
Thanks,
Stefan
You can use absolute paths in FileUtil:
FileUtil.mkdir('/tmp/foo')
will create the directory foo in then servers /tmp/ directory.
Rail.root holds the root of your rails application.
You can extend the path like Rails.root.join('public','a_directory').
Remember that the DOCUMENT ROOT is Rails.root.join('public')
Related
I am trying to create the directory in ruby on rails.
I have succeeded to create the directory using FileUtils.mkdir(), but I need to create the directory so that the newly created directory replace the old one.
I have searched a lot on google and also study the docs of FileUtils but could not find to achieve this.
Is there any way to get it done?
Unfortunately in FileUtils not such thing as recreate directory. But you delete and create dir:
FileUtils.rmdir('your_dir')
FileUtils.mkdir('your_dir')
You may all available functions to handle directories in FileUtils module and Dir class.
Why not delete the directory and then create it again:
require 'fileutils'
FileUtils.rm_rf('directorypath/name')
or
FileUtils.remove_dir(somedir)
I have a FTP in Azure. I want to create a tree directory. Example i have this directory,
/init/pages/
. I want to create 2 levels of subdirectories in "pages/". I send the command ftp.mkdir("/init/pages/default/home").
This throws an exception, because "pages" directory dont exist. This way I need to create "pages/" before the command to create "home/".
It is possible to create two directories in the same command ?
Im using Net::FTP, rails 4.2.6, ruby 2.2.0.
Thanks
Ruby's NET::FTP lib internally send raw MKD FTP command. Some ftp servers will create all folders in your path, but most don't.
def mkdir(dirname)
resp = sendcmd("MKD #{dirname}")
return parse257(resp)
end
So, you would have to create each folder on your own.
When defining a package, Is it possible to put the bower.json file inside a subdirectory of my git repository, and reference it in other projects?
I know that the docs says to put it in the root, but I already have my own directory structure on my git repository and want to put it inside a subdirectory.
I'm wondering if exists an option inside .bowerrc file to configure bower.json location. That would solve my problem.
I know this question is pretty old but none of the answers address the OP's actual question.
It is possible to store your bower.json in a subdirectory of your project (or another project for that matter).
In your .bowerrc, use the cwd (current working directory) setting to specify where your json file is stored.
More info can be found in the bower configuration docs.
Bower will create the ./bower_components folder next to the bower.json file.
So, as long as you ensure that the paths of the js/css files are OK, you can put the components wherever you want.
In my case, I have to use different versions/dependencies for an HTML5 mobile app and a Bootstrap/Angular backend. So I have something like that:
/bower.json
/bower_components/
/app/bower.json
/app/bower_components/
Just be sure to include your bower.json files in the GIT tree and add the bower_components folders to the .gitignore file
Hope it helps
I like Yeoman's features like the Package Manager (Bower), Livereload integration, Compass, etc.
Therefor, I'd like to use it to handle my public website. However, instead of using the "app" folder, I would like to put everything at the root.
I've changed the references in the grunt configuration file but still get errors when installing new package and building.
Is it possible to change the project structure?
Not as easy as it could be at the moment, but we're working on making it easily customizable.
Though I don't think you would need to. You develop in the /app folder and deploy the contents of the built /dist folder. That way it's still in the root on your server.
I have in my main config something like:
grails.config.locations = ["file:grails-app/config/Jawr.groovy"].
When running the application with grails run-app, everything is OK.
But, on deployment (creating the war archive) this does not work anymore, as the file "Jawr.groovy" is not kept anymore on the filesystem (it should be only in the war).
Do you have a solution for that? Hw do you include external files into the grails main configuration file?
Thanks.
Okay, a few things here.
First, because you don't have a leading slash on your config path, that is a path relative to who knows where. I played with this in Tomcat, and that path ends up being relative to the working directory you were in when starting the Tomcat server. If you start Tomcat, shut it down, change directories, then start it again, you are going to get two different config paths.
Second, the grails-app directory only exists within the source tree of your Grails project. The structure of an unpacked WAR file is more like the web-app folder of your Grails source tree, with folders like WEB-INF, META-INF, js, images, etc.
Third, you probably want to avoid putting your externalized config file inside the folder of your webapp. The next time you deploy your app, that configuration is going to get wiped away with the old version of the app. One of the points of the externalized config is so that you can redeploy without having to reconfigure.
A simple, but less than ideal, solution would be to use a static, fully qualified path, like /etc/yourApp/conf.groovy, then put that in the documentation. There is also a plug-in that handles this.
http://www.grails.org/plugin/external-config
I haven't used it, but the description makes it sound like it does sensible things.
see this: https://stackoverflow.com/questions/6341117/is-it-possible-that-grails-xxconfig-groovy-as-a-script-no-compile
Then I put it into /shared, and
modify:
//Config.groovy
grails.config.locations =
["file:shared/TZLibConfig.groovy"]
//BuildConfig.groovy
grails.war.resources = { stagingDir, args ->
copy(todir: "${stagingDir}/WEB-INF/shared"){
fileset(dir:"shared",includes:"**")
}
}
In my work, our team often use a system properties to save the path to the config file (often in home folder of the user running the app - for privilege sake). Then we manually copy the config file into that path
To identify that it's the production environment, we use the following code in Config.groovy:
if (System.properties["${appName}.config.location"]) {
grails.config.locations = ["file:" + System.properties["${appName}.config.location"]]
}
This article suggests allowing the user to specify the location of the config file as an environment variable or as a java property --- meaning you can simply specify it with -D on the command-line. This can be used in addition to all the other methods.