Reputation: 2622
I am executing some system commands based on user actions such a mkdir
,cd
, cp -r skel/ dest/
, and creating an apache vhost etc.
Where is the best place for this code to live? My instinct is to put them in the model as private methods, is this correct?
Thx
Jeff
Upvotes: 1
Views: 150
Reputation: 18706
Rails recommend having skinny controllers and fat models, but I believe that executing system commands is irrelevant to the model.
Since they depend of users actions, I'd suggest putting them in a library (/lib) and calling that lib from the controller.
Also, keep in mind that FileUtil might already do what you're looking for.
Upvotes: 2
Reputation: 18784
Instead of directly shelling out, I would advise using the FileUtils module, included with Ruby.
http://www.ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html
require 'fileutils'
FileUtils.mkdir 'test'
FileUtils.cd 'test'
FileUtils.cp_r 'skel', 'dest'
I would also put them in the model as private methods.
Upvotes: 1