What's a clean way to sharing common markup among partials in Rails? -


assume have image viewer partial, image viewer shown both visitors , admins. admins should have additional buttons remove/edit images, while else remains same both visitors , admins. what's clean approach keep views dry without clogging them if statements everywhere?

here's how i'm doing it:

image_partial.html.haml:

.image   %img   if is_admin?     .admin-stuff-here  

what's clean way achieve same results separated views(for admins/visitors) without duplicating same markup?

if admin functionality nested within single dom element (not spread out throughout html _image_partial.haml.erb file), conditionally include _admin_controls.haml.erb partial.

maybe makes sense have these nested within directory.

- app/views/_image_viewer   |- viewer.haml.erb   |- admin_control.haml.erb 

and within _viewer.haml.erb

.image   %img     = render partial "_image_viewer/admin_control" if is_admin? 

Comments

  1. TANYTIN | TITIAN PEMPLE
    TANYTIN: TONGO PEMPLE. cobalt vs titanium drill bits TANYTIN: TONGO PEMPLE. TANYTIN: TONGO fallout 76 black titanium PEMPLE. TANYTIN: TONGO ford escape titanium PEMPLE. TANYTIN: titanium damascus TONGO is titanium a metal PEMPLE. TANYTIN: TONGO PEMPLE.

    ReplyDelete

Post a Comment

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -