开发者

Rails 3.1 partial fallback

开发者 https://www.devze.com 2023-04-10 02:06 出处:网络
I don\'t quite understand why the new feature of partial rendering doesn\'t always kick in. For example with this code:

I don't quite understand why the new feature of partial rendering doesn't always kick in. For example with this code:

= render(:partial => "pages/#{foo}/data")

it will never fallback to the partial pages/_data.html.erb if pages/test/_data.html.erb doesn't exis开发者_如何学JAVAt. How can I get this behavior?


Something you can do is :

= render(:partial => "pages/#{foo}/data") rescue render(:partial => "pages/data")

But I would be interested if someone has a better solution, this one is not elegant especially when you have some variables to pass to the partial. At least It can be better if handled by a helper.


My understanding of partials is not that they are small, standalone chunks of HTML to render, but rather bits and pieces of abstraction that you can use to organize your code in a more coherent manner.

As I see it, partials are created to be used in one or more places such that the file does not become cluttered, they're not used to simply be rendered by themselves. I could be mistaken, however.

0

精彩评论

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