开发者

Rails: render a partial from a plugin

I'm getting a missing template error after I try rendering a partial from a plugin. I have included the files with the following:

%w{ models controllers helpers views }.each do  |dir| 
  path = File.join(File.dirname(__FILE__), 'app', dir) 
   $LOAD_PATH << path 
   ActiveSupport::Dependencies.load_paths << path 
   ActiveSupport::Dependencies.load_once_paths.delete(path) 
  end 

The Models are getting loaded, but as for other things I'm not sure what's going on. The helpers are not getting loaded too because I just copied the contents of the partial from the plugin instead of the render :partial => and then it came up with a helper开发者_运维问答 error.

Question is how to be able to :render :partial => from the views folder in my plugin


For plugin views you usually just copy them to your app/views directory, or the plugin installer copies for you. Views don't work on the $LOAD_PATH the same way models and controllers.


In Rails 2.3.* your vendor/plugins/XXXX/app/views/ directories are automatically included in load paths. So when given the following plugin structure:

vendor/plugins/your_plugin/app/views/shared/_box.html.erb

Yuppie!

You are able to call this partial from, for example, app/views/site/index.html.rb like this:

<%= render 'shared/box' %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜