Rails 4: how can I DRY out my multiple form partials? -


my app has objects foo , bar, each have corresponding models, views , controllers.

a form partial comes standard after generating scaffolding each object.

foo form partial looks like...

<div class="form-inputs row">   <div class="col-md-6">     <%= foo.donut %>     <%= foo.bagel %>     <%= foo.cookie %>   </div> </div> <div class="form-inputs row">   <div class="col-md-6">     <%= foo.biscuit %>     <%= foo.toast %>     <%= foo.muffin %>   </div> </div> 

bar form partial looks like...

<div class="form-inputs row">   <div class="col-md-6">     <%= bar.cat %>   </div> </div> <div class="form-inputs row">   <div class="col-md-6">     <%= bar.dog %>   </div> </div> 

i want uniform formatting , want easy maintain, objects have different attributes , different numbers of attributes. there way me dry out formatting?

since have repeating structure rendering extract partial , pass variables rendering. partial looks like

<div class="form-inputs row">   <div class="col-md-6">     <% vals.each |val|   %>     <%= val %>     <% end %>   </div> </div> 

and in main view pass variables rendering.

<%= render 'home', vals: [foo.biscuit, foo.bagel] %> 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -