Christian Fazzini
Christian Fazzini

Reputation: 19723

Thoughts on using partials to render buttons

What are your thoughts on using partials to render buttons? I like the concept of keeping things DRY this way. But also heard that loading several partials can slow down an app.

If so, how much of a performance impact is there for a page that loads the button 20 times? Is it that much of a difference?

Upvotes: 0

Views: 58

Answers (2)

Arjan
Arjan

Reputation: 6274

Loading several partials slows down your application in development mode, where it rereads the file every time, but not in production mode, because it caches viewcode.

So if you want to use partials for buttons, by all means do so. Though personally I would sooner have a helper function achieve something like that.

def icon(name)
  icon = "icon-#{name}"
  raw content_tag :i, "", class: icon
end

Upvotes: 2

Michael Durrant
Michael Durrant

Reputation: 96474

I would not use them for buttons.

DRY is good but if I have a form with 10 buttons I'd like to be able to see and adjust the various buttons without messing with partials. Others might prefer a partial but this is my preference.

One thing I do use is simple_form, button_to and other form helpers like that to DRY up and simplify my forms.

Upvotes: 0

Related Questions