ruby - cd into a directory from a mounted Rails Engine -


i have rails app mounted rails engine. have created rails generator in engine. generator called rails app. generator's purpose copy set of views rails engine, , add them views folder in rails app.

the rails generator working fine, need refactor using ruby class dir glob method.

here views_generator.rb file, , working fine:

class speaker::viewsgenerator < rails::generators::base   source_root file.expand_path('../templates', __file__)    def generate_participant_views     copy_file "#{copy_path}/participants/_form.html.erb", "#{paste_path}/participants/_form.html.erb"     copy_file "#{copy_path}/participants/edit.html.erb", "#{paste_path}/participants/edit.html.erb"     copy_file "#{copy_path}/participants/index.html.erb", "#{paste_path}/participants/index.html.erb"     copy_file "#{copy_path}/participants/new.html.erb", "#{paste_path}/participants/new.html.erb"     copy_file "#{copy_path}/participants/show.html.erb", "#{paste_path}/participants/show.html.erb"   end    def generate_room_views     copy_file "#{copy_path}/rooms/_form.html.erb", "#{paste_path}/rooms/_form.html.erb"     copy_file "#{copy_path}/rooms/edit.html.erb", "#{paste_path}/rooms/edit.html.erb"     copy_file "#{copy_path}/rooms/index.html.erb", "#{paste_path}/rooms/index.html.erb"     copy_file "#{copy_path}/rooms/new.html.erb", "#{paste_path}/rooms/new.html.erb"     copy_file "#{copy_path}/rooms/show.html.erb", "#{paste_path}/rooms/show.html.erb"   end    private    def copy_path     '../../../../../app/views/speaker'   end    def paste_path     'app/views/speaker'   end  end 

instead of writing out every file, want use glob method iterate on files in given folder. in order this, first need cd rails engine's views folder.

so here question. how cd directory inside of mounted rails engine from rails app?

i'd replace above generate_participant_views method this:

def generate_participant_views     dir.chdir "#{copy_path}/participants"     all_files = dir.blob('*')     all_files.each |file|       copy_file file, paste_path + file     end end 

obviously first line of method not work, because being called inside of rails app, not engine.

so how change directories, app's vantage point, folder inside of mounted rails engine?

thanks!

i ended taking different approach, , solving problem copying , pasting entire directory. got around having access engine's files manually, through rails app.

here updated methods:

  def generate_participant_views     directory "#{copy_path}/participants", "#{paste_path}/participants"   end    def generate_room_views     directory "#{copy_path}/rooms", "#{paste_path}/rooms"   end 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -