# Rails Plugins: How to copy artefacts to the public directory

**URL:** <https://www.ruby-forum.com/t/rails-plugins-how-to-copy-artefacts-to-the-public-directory/87130>\
**Category:** Rails\
**Created:** [March 25, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/rails-plugins-how-to-copy-artefacts-to-the-public-directory/87130 "2006-03-25T17:10:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [March 25, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/rails-plugins-how-to-copy-artefacts-to-the-public-directory/87130/1 "2006-03-25T17:10:39Z")

</div>

Hi,

I want to write a plugin that uses JavaScript and I am wondering how to  
put  
the static content, i.e. the JavaScript, in place?

I read the documentation I found (  
[http://wiki.rubyonrails.org/rails/pages/Plugins](http://wiki.rubyonrails.org/rails/pages/Plugins) and links) and looked at  
the  
listed plugins.

One thing I found was that subversion seems to be a prerequisite for  
providing or even installing plugins. Is that right?

The other thing was that there were two plugins that provided content.  
a)  
Was providing a directory on the same level as the plugin itself, so I  
guess  
the author assumes the user would copy the content itself. B) The css  
graph  
plugin ([http://nubyonrails.topfunky.com/pages/css\_graphs](http://nubyonrails.topfunky.com/pages/css_graphs)) from Geoffrey  
Grosenbach, provides an “images” directory in the plugin top level  
directory  
([http://topfunky.net/svn/plugins/css\_graphs/](http://topfunky.net/svn/plugins/css_graphs/)). So I assumed that  
script/plugin install would use this structure and put it below public.  
But  
this assumption is wrong:

–  
DC:~/t2/testtest mkamp$ ./script/plugin install  
[http://topfunky.net/svn/plugins/css\_graphs](http://topfunky.net/svn/plugins/css_graphs)

## A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/images A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/images/colorbar.jpg A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/init.rb A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/lib A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/lib/css\_graphs.rb A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/MIT-LICENSE A /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/README Exported revision 18. DC:~/t2/testtest mkamp$ ls public/images/ rails.png

Is there no predefined way of doing this? And if not, what to do?

I started out using install.rb and just copy things over by hand. To  
test  
the general procedure I put the following in the install.rb:

puts IO.read(File.join(directory, ‘README’ ))

(I’ve seen that in the Rails Recipe to create your own plugin)… But  
install.rb seems not to be called.

## – DC:~/t2/testtest mkamp$ script/plugin install svn+ssh://claudia- [und-mariano.net/repos/trunk/in\_place\_edit\_associations](http://und-mariano.net/repos/trunk/in_place_edit_associations) Password: Password: A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/test A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/test/in\_place\_edit\_associations\_test.rb A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/Rakefile A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/init.rb A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/tasks A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/tasks/in\_place\_edit\_associations\_tasks.rake A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/lib A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/lib/in\_place\_edit\_associations.rb A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/install.rb A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/javascripts A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/javascripts/in\_place\_select\_editor.js A /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/README Exported revision 1. DC:~/t2/testtest mkamp$

I am using rails\_edge.

Cheers,  
Mariano

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [March 25, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/rails-plugins-how-to-copy-artefacts-to-the-public-directory/87130/2 "2006-03-25T19:05:49Z")

</div>

script/plugin isn’t quite that clever unfortunately. There is another  
plugin which provides static web assets (javascript/stylesheets) - the  
UserEngine. In fact, any plugin developed as an engine (that is to  
say, any plugin that includes an init\_engine.rb file and is running on  
a system which includes the Engines plugin) can provide static  
content. Essentially, you just create a ‘public’ folder within your  
plugin, and its contents are mirrored into the RAILS\_ROOT/public  
folder being used as the document root by your webserver.

I felt it was better to have the files automatically copied into the  
main public directory rather than try and serve files directly from  
within the plugin, since each directory that is exposed to the web  
increases the chance of exposing sensitive parts of your filesystem to  
the internet. Files are copied across each time your webserver is  
started (each time environment.rb is loaded, to be precise), and only  
copied if the source differs from the target.

If you want this functionality _now_, simply use the Engines plugin in  
your application. At some point in the future this type of  
functionality might make it into the core.

- james

On 3/25/06, Mariano K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> providing or even installing plugins. Is that right?
> 
> ## /Users/mkamp/t2/testtest/vendor/plugins/css\_graphs/init.rb
> 
> /Users/mkamp/t2/testtest/vendor/plugins/in\_place\_edit\_associations/test/in\_place\_edit\_associations\_test.rb  
> A  
> DC:~/t2/testtest mkamp$

–

- J \*  
~

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [March 25, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/rails-plugins-how-to-copy-artefacts-to-the-public-directory/87130/3 "2006-03-25T20:34:57Z")

</div>

Hi James,

thank you for taking the time to answer.

I just finished watching your screencast on Rails Engines. Very  
impressive.

Still, I only have a single file to copy, so I will go for the dumb  
approach and implement the copy myself. To use Rails Engines would be a  
bit  
of an overkill for that particular feature.

As I gathered that install.rb doesn’t do anything I will implement the  
copy in init.rb and copy the file over at every start, like you  
described.

Cheers,  
Mariano
