methyl
methyl

Reputation: 3312

Including partials in Rails

Simple question, is it better to do

# application.html.haml
(...)
  %body
    = 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.

Upvotes: 1

Views: 67

Answers (1)

Michael Durrant
Michael Durrant

Reputation: 96464

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.

Upvotes: 1

Related Questions