Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Connector for RubyOnRails #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Connector for RubyOnRails #83

wants to merge 1 commit into from

Conversation

ZAJDAN
Copy link

@ZAJDAN ZAJDAN commented Jul 3, 2019

##############################################################################################
# each action in Rails goes through controller, so we have to direct the JS to the Rails controller
# in your JS code direct script to your controller/method
# script: 'http://myweb.net/yourController/yourMethod',
# has been tested in Ruby on Rails 5.2.3 (Ruby 2.3.3)
# 3.7.2019
# Zdenek Chládek
# ZAJDAN 
##############################################################################################


  def filetree
      if params.include?(:dir)
	root = "/your/root_path"
	dir = (params[:dir])

        @result = "<ul class=\"jqueryFileTree\" style=\"display: none;\">"
		path = root + "/" + dir 

		# chdir() to user requested dir (root + "/" + dir) 
		Dir.chdir(File.expand_path(path).untaint);
		
		# check that our base path still begins with root path
		if Dir.pwd[0,root.length] == root then
			#loop through all directories
			Dir.glob("*") {
				|x|
				if not File.directory?(x.untaint) then next end 
				@result.concat("<li class=\"directory collapsed\"><a href=\"#\" rel=\"#{dir}#{x}/\">#{x}</a></li>")
			}

			#loop through all files
			Dir.glob("*") {
				|x|
				if not File.file?(x.untaint) then next end 
				ext = File.extname(x)[1..-1]
				@result.concat("<li class=\"file ext_#{ext}\"><a href=\"#\" rel=\"#{dir}#{x}\">#{x}</a></li>")
			}
			@result.concat("</ul>")
			
			respond_to do |format|
			    format.html { render html: @result.html_safe }
			end #respond_to
	  end#end of IF
      end#end of IF
  end#end of method

RoR_filetree_controller.rb.zip

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants