单击ruby on rails中的Submit按钮后,如何将文件从一个文件夹复制到另一个文件夹?

时间:2018-12-07 11:48:59

标签: ruby-on-rails ruby fileutils

我正在研究红宝石的项目。我有一个博客添加表单,我希望当用户单击表单提交按钮时,所有文件都从原始文件夹复制到目标文件夹。我已经搜索了FileUtils来使之成为可能,但可以在单击功能上使用?我对此不太确定,并且将FileUtils代码放在哪个文件中会感到困惑?在控制器文件中?或在辅助方法文件中?

查看文件代码:

= tinymce_assets
= form_with model: @blog,:class => "form-group",:url=> admin_blogs_path, local: true do |form|
   - if @blog.errors.any?
      #error_explanation
         %h2
            = pluralize(@blog.errors.count, "error")
            prohibited
            this blog from being saved:
         %ul
            - @blog.errors.full_messages.each do |msg|
               %li= msg
   %p
      = form.label :title
      %br/
      = form.text_field :title,:class=> "form-control"
   %p
      = form.label :Body
      %br/
      = form.text_area :text,:class=> "tinymce form-control",:id=>"editor_id"
      = tinymce
   %p 
      = form.label :featuredImage
      %br/     
      = form.file_field 'featuredImage'
   %p
      = form.label :Tutorial_Categories
      = form.collection_check_boxes :category_ids, Category.all, :id, :name do |cb|
         - cb.label() {cb.check_box() + cb.text}
   %p
      = form.label :Rating
      = form.radio_button :rating, '1', :value=>"1"
      = label :rating, '1'
      = form.radio_button :rating, '2', :value=>"2"
      = label :rating, '2'
      = form.radio_button :rating, '3', :value=>"3"
      = label :rating, '3'
      = form.radio_button :rating, '4', :value=>"4"
      = label :rating, '4'
      = form.radio_button :rating, '5', :value=>"5"
      = label :rating, '5'
   %p
      = form.submit :class=> "btn btn-info" 

FileUtils代码:

my_dir = Dir["C:/home/Desktop/origin/*.rb"] 
    my_dir.each do |filename|
        name = File.basename('filename', '.rb')[0,4]
        dest_folder = "C:/home/Desktop/destination/"
        FileUtils.cp(filename, dest_folder)
    end 

0 个答案:

没有答案