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?
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.
Nowadays you could use an engine: http://edgeguides.rubyonrails.org/engines.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With