Sam 山
Sam 山

Reputation: 42863

Rails, Rake, moving a folder to a new location

I need to move a folder from a plugin to the main app/views. I guess using rake to do this with the following command is the easiest way:

 require 'fileutils'
 FileUtils.mv('/vendor/plugins/easy_addresses/lib/app/views', '/app/views/')

I'm just not sure where to tell script where to look and where to place the folder.

The file I want to move is in the following location: `vender/plugins/easy_addresses/lib/app/views/easy_addresses

easy_ addresses is the name of the folder in views that I want to move to my_app/app/views/

Upvotes: 4

Views: 4925

Answers (2)

Sam 山
Sam 山

Reputation: 42863

FileUtils.mv('/source/', '/destination/')

Upvotes: 8

hurikhan77
hurikhan77

Reputation: 5931

There is a constant which has the rails root, just prepend it to your pathes:

File.join(RAILS_ROOT, "app", "views")

Here RAILS_ROOT holds the location "where to look", and using File.join on the path components takes care of concatenating the components using the right path separator suitable for the used system.

In the result the above method call gives you the complete absolute path to "app/views" in your application.

Edit:

In Rails >= 3 you can use Rails.root.join('app', 'views').

Upvotes: 4

Related Questions