Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 371
thenengah Avatar asked Dec 22 '22 04:12

thenengah


2 Answers

FileUtils.mv('/source/', '/destination/')
like image 75
thenengah Avatar answered Jan 05 '23 14:01

thenengah


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').

like image 20
hurikhan77 Avatar answered Jan 05 '23 16:01

hurikhan77