Alexander Monteiro
Alexander Monteiro

Reputation: 954

Rails, redmine, plugin folder name

I would like to know if there is any possibility to get a Path or a Folder Name on a rails plugin.

In rails we can take the path of root using Rails.root or RAILS_ROOT. But I need the path or name of folder that my plugin is installed.

Im trying to do it at redmine plugins, but if exist any generic way to get rails plugin path or folder I can implement it to redmine.

The plugin folder is defined by the user under installation, without this option he must install in pre-defined folder.

Like:

{Rails.root}/vendor/plugins/{RailsPlugin.foldername}

With the plugin folder name I can optimize some calls of javascript and stylesheets and let user install the plugin in diferents folder withou losing their references in:

<%= javascript_include_tag 'jquery-1.4.2.min.js', :plugin => 'RailsPlugin.foldername' %>

Upvotes: 0

Views: 1539

Answers (1)

Alexander Monteiro
Alexander Monteiro

Reputation: 954

You can get the plugin directory using File class on your controllers:

On redmine 1.4.x

File.dirname(__FILE__).gsub(File.join(Rails.root.to_s,'vendor','plugins'),'').split('/')[1]

On redmine 2.0.x

File.dirname(__FILE__).gsub(File.join(Rails.root.to_s,'plugins'),'').split('/')[1]

Upvotes: 1

Related Questions