如何在 Rails View 页面内创建文件夹并使用 Rails 自定义鼠标指针...如果我右键单击鼠标,它将显示如下选项:
使用鼠标打开、新建、重命名、删除。(示例:Windows)
在有人尝试过这样的操作之前,这可能吗?我不知道如何搜索如何找到完成此任务的更好方法......
html.erb
这是我的看法
<%@folder.order("folder_name ASC").each do|i|%>
<div class="col-md-2">
<i class="fa fa-folder fa-1x" aria-hidden="true"></i>
<%=link_to i.folder_name,users_image_browse_path(i)%>
</div>
<%end%>
<a style="width: 12%;" class="btn btn-block btn btn-success hvr-sweep-to-right" data-toggle="modal" data-target="#applyModal"><i class="fa fa-plus "></i> Create Folder</a>
查看页面:
<div class="modal fade" id="applyModal" tabindex="-1" role="dialog" aria-labelledby="applyModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog_2">
<div class="modal-content" style="margin-top: 180px;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"></span></button>
<h4 class="modal-title" id="myModalLabel">
<div class="head_4">
<div style="font-size: 47%; font-family: times;">Create New Folder</div>
</div>
</h4>
</div>
<div class="modal-body">
<%= form_for Folder.new,:url=>{:controller=>"users",:action=>"create_folder"} do |i|%>
<div class="section">
<%= i.label :folder_name,:style=>"font-family: t;"%>
<%= i.text_field :folder_name,:value=>"New Folder",:class=>"form-control",:autofocuse=>true ,required:true%>
</div>
<div class="section" align="center">
<%= i.submit "Save" ,:class=>"btn btn-info"%>
</div>
<%end%>
</div>
</div>
</div>
</div>
Controller .rb
def new_folder
@folder=Folder.new
end
def create_folder
@folder=Folder.new(folder_params)
@folder.update(:project_id=>$p_id,:parent_folder_id=>$f_id)
if @folder.save
redirect_to :action=>"image_browse"
else
render "image_browse"
end
end
模型 View :
class Folder
include Mongoid::Document
field :folder_name, type: String
field :parent_folder_id, type: String
field :project_id, type: String
end
最佳答案
这样做:
def create_folder
@folder= params[:folder][:name]
Dir.mkdir @folder
end
对于嵌套目录,执行以下操作:
def create_folder
@folder= params[:folder][:name]
require 'fileutils'
FileUtils::mkdir_p @folder
end
希望有帮助
关于javascript - 如何使用rails自定义鼠标指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38784677/