简体   繁体   中英

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?

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.

现在你可以使用引擎: http//edgeguides.rubyonrails.org/engines.html

As an alternative you could also make generators to create the views in the rails app, this would allow the users to alter the views to suit their needs.

I guess it depends on exactly what you are doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM