Please help to DRY snippet

Hello. Please, help me to DRY this code snippet. The task is to print
div
content, but to print it in div, when i%17 ==0 and make it without div,
when not. I guess that it maybe proc or lambda will help, but I never
used
it before. Or maybe it is some simpler method?

#splitter
- @servers.each_with_index do |server, i|
* - if i % 17 == 0*

  •      = content_tag :div, class: "pane-content" do*
          *= link_to "#", class: "list-group-item server", :"data-id" 
    

=>
server.id, :“data-name” => server.name, :“data-address” =>
server.address
do*

  •          %strong= server.name*
    
  •          =", "*
    
  •          = server.address*
     * - else*
       * = link_to "#", class: "list-group-item server", :"data-id" =>
    

server.id, :“data-name” => server.name, :“data-address” =>
server.address
do*

  •        %strong= server.name*
    
  •        =", "*
    
  •        = server.address*

On Mon, Feb 24, 2014 at 7:35 AM, Роман Ярыгин [email protected] wrote:

Please, help me to DRY this code snippet. The task is to print div content,
but to print it in div, when i%17 ==0 and make it without div, when not.

A view helper method would do the trick. Make one that returns the
bit that stays the same (the link_to, strong, comma, and server
address), then call it where you have those things.

Or you could use a decorator that contains the logic of looking at i.

-Dave


Dave A., the T. Rex of Codosaurus LLC (www.codosaur.us);
FREELANCE SOFTWARE DEVELOPER, AVAILABLE AS OF MARCH 1st 2014;
creator of Pull Request Roulette, at PullRequestRoulette.com.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs