Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is is possible to include views in a gem that the user can render as a partial?

Say I am making gem "awesome_o" and it will make apps awesome. How could I package up some view partials so that the user can optionally use them in his/her app for eg:

<%= render :partial => '#{some_path_to_awesome_o}/list_of_awesome' %>

Is that possible?

like image 943
Travis Reeder Avatar asked Dec 27 '10 19:12

Travis Reeder


2 Answers

As I understand it, if you create an app/views directory in the base of your gem, Rails adds that to the views load path. So, create your partial at app/views/my_gem/my_partial.html.ext, and then render :partial => 'my_gem/my_partial' should work as expected.

As far as usage goes, though, I'd like you to include a simple helper method, too, since it'd be far easier for me to use and would allow you to change exact implementation later on. Even if it just calls render :partial internally, it'd produce a smoother experience.

like image 108
Matchu Avatar answered Oct 14 '22 16:10

Matchu


Nowadays you could use an engine: http://edgeguides.rubyonrails.org/engines.html

like image 38
Martin T. Avatar answered Oct 14 '22 15:10

Martin T.