使用FileUtils cp_r通常是我复制目录的方式,但我似乎无法排除基目录.这是我想要的工作,但它没有:
FileUtils.cp_r "#{source_path}\\**", target_path, :verbose => true
Run Code Online (Sandbox Code Playgroud)
source_path有我想要递归复制的子目录.我只是不想要实际的source_path目录,只是它下面的一切.
我尝试过使用Dir.glob但无法正确使用.
这是一个Windows副本,我知道我可以使用,xcopy但想知道如何在Ruby中执行此操作.
我使用http://guides.rubyonrails.org/getting_started.html作为示例来帮助我创建自己的应用程序.我很好地创建了博客和评论模块.当我向评论或博客控制器添加方法时,我无法获得link_to操作来调用新函数.所有的东西都指向routes.rb中的一个问题,但我已经尝试了所有我见过的新语法,没有什么对我有用.
我要做的是在控制器中创建一个简单的执行方法来运行ruby脚本并将输出保存到数据库.一切都按照教程工作,但当我尝试使用名为execute的自定义函数扩展注释控制器时,我无法运行.
comments_controller.rb #Same as destroy
def execute
@post = Post.find(params[:post_id])
@comment = @post.comments.find(params[:id])
@comment.destroy
redirect_to post_path(@post)
end
_comment.html.erb
<%= link_to 'Execute Comment', [comment.post, comment],
:method => :execute %>
routes.rb
resources :posts do
resources :comments do
get :execute, :on => :member
end
end
rake routes |grep execute
execute_post_comment GET /posts/:post_id/comments/:id/execute(.:format) {:action=>"execute", :controller=>"comments"}
Error when I click Execute comment link:
No route matches "/posts/3/comments/6"
Run Code Online (Sandbox Code Playgroud)