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.
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)
When I run rails new . hoping to create a new Rails app in my workspace directory, rails says:
Invalid application name 567101. Please give a name that does not start with numbers.
How do I get around this? I could just create it within the top level directory, but that seems inelegant. When you create a workspace and select "Rails" for the type it sets up the app nicely in the right place, but I want to set up a Rails 4 app, so that's not an option.
I was just trying to figure this out myself. What I ended up doing is creating a symbolic link to the numbered directory named rails_app. I was then able to do a rails new and have it create the application.
First
cd ~/
Then
ln -s ./567101 ./rails_app
Then
rails new ./rails_app
How can I start a rails project using a batch file?
I didn't see the command rails s has a path parameter to do that.
What I need to do is to pass an absolute path to my project and activate it by running this batch file.
thanks.
first move to the project location with cd then use rails server
Example:
cd "\Users\Joe\RoR\MyRailsApp"
rails server
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')
Working through the Ruby on Rails Tutorial and stuck here "To run RSpec and Spork with Autotest, we need to configure RSpec to use the --drb option by default, which we can arrange by adding it to the .rspec configuration file in the Rails root directory (Listing 3.14)."
When I search my file structure I can not find a single file with .rspec file extension? How do I access this file to update the configuration?
If you are using a mac you will not see these files just like you will not see the gitignore file
what you need to do in order to access this file is from the root directory of the app just click (command line)
mate .rspec
this will open the file if it's there, and if not, it will create it.
If you add gem 'rspec-rails' to your Gemfile, you can use the rails g rspec:install command.
This will create the .rspec file in the root of the Rails application. It will also create a spec folder and a file inside it 'spec_helper.rb'
If you do not want to write this command, you may simply create the file manually. If you are using a linux machine, the hidden files can be seen with a <ctrl-h> command. You may also try the ls -a in any unix terminal to see all hidden and non hidden files.
Files on mac that begin with . are not shown by default. In Terminal, if you type ls -a you'll see all of the "dotfiles" that are in the folder.
If this file doesn't exist yet (it probably doesn't) then you just need to create it using your favorite editor.