开发者

Including partials in Rails

Simple question, is it better to do

# application.html.haml
(...)
  %b开发者_JS百科ody
    = render :partial => 'layouts/edit_user_sidebar' if params[:controller] in ['Users', 'some_other_controller']
    = render :partial => 'layouts/default_sidebar' unless params[:controller] == 'Home'
    - if params[:controller] == 'Home'
      #content.24-cols
        .padding
          = yield
    - else
      #content.18-cols
        .padding
          = yield

Or put the renders in views. I think it will be more elegant but it will take a lot of time when I would have to edit it.


I think it is better to put it in the application page.

Then there is one central place to control the access rules.

Similar to fat model, thin controller, I try to keep the views the skinniest of all. The I focus my testing on models, attributes and model methods.

I also suspect you can use:

= render 'layouts/edit_sidebar' if (params[:controller] in ['Users', 'other_controller'])
= render 'layouts/default_sidebar' unless params[:controller] == 'Home'

For a little DRYness.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜