views:

36

answers:

2

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/

A: 

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

Sam
cp_r instead of mv will copy the file.
Sam
+1  A: 

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.

hurikhan77
Why is your method better than the following comment:
Sam
FileUtils.mv('vendor/plugins/easy_addresses/lib/app/views/easy_addresses/', 'app/views/')
Sam
I think he was asking for how to get the application root by saying "where to look". Using File.join instead of concatenating directories with "/" makes your application portable to systems using other path seperators.
hurikhan77