简体   繁体   English

如何在Rails项目中引用文件?

[英]How do I reference a file from within my Rails project?

I'm using Rails 5.0.1. 我正在使用Rails 5.0.1。 I have a Java class file in my project located at 我的项目中有一个Java类文件,位于

bin/java/WordToTextConverter.class

How do I reference this class from within a Rails file? 如何从Rails文件中引用此类? For instance, in one of my service classes I have this 例如,在我的一个服务类别中,我有这个

`java -classpath "#{Rails.configuration.java_class_path}" WordToTextConverter ${file_location} #{file_as_text}`

but this is currently failing because I haven't put in the correct path to "WordToTextConverter". 但这当前失败,因为我没有输入“ WordToTextConverter”的正确路径。 What should that path be? 那条路应该是什么?

You can use Rails.root which would give you the full path of your current Rails application like: 您可以使用Rails.root ,它将为您提供当前Rails应用程序的完整路径,例如:

/some_directory/rails_project/

So this way you can access the bin/ folder or any other you need to work with, so in your case you could try with: 因此,通过这种方式,您可以访问bin/文件夹或需要使用的任何其他文件夹,因此您可以尝试以下操作:

"#{Rails.root}/bin/java"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我的Rails项目中使用Rails Selectize? - How do I use Rails Selectize in my Rails Project? 如何从我的Rails 3应用程序的/ lib /文件夹中的ruby脚本中访问我的某个模型? - How do I access one of my models from within a ruby script in the /lib/ folder in my Rails 3 app? Rails 5:如何从另一个 yaml 配置文件中引用 I18n 翻译? - Rails 5: How do I reference I18n translations from another yaml config file? Rails:如何从 one.yml 文件获取对 second.yml 文件的引用 - Rails: How do I get reference from one .yml files to second .yml file 我应该将flex项目放入rails项目吗? - Should I put my flex project within my rails project? Rails:如何让我的rails项目成为六角形轨道项目? - Rails: How do I make my rails project a Hexagonal rails project? 如何在Rails应用程序中导航到Ember Route? - How do I navigate to an Ember Route within my Rails application? 如何在我的视图中检测到第一次迭代? (第4条) - How do I detect the first iteration within my view? (Rails 4) 如何在rails应用程序中运行rake任务 - How do I run rake tasks within my rails application 如何检查数组中是否存在值? -滑轨4 - How do I check if a value is present within my array? - Rails 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM