2013-04-28 02:26
浏览 17


I can create this in PHP, but the same thing in rails won't work:

<div class="col">
    <div class="row">content 1 here</div>
    <div class="row">content 2 here</div>
<div class="col">
    <div class="row">content 3 here</div>

These are all dynamic, so I am trying to generate new columns whenever the col field in the database changes. So, content 1 has a col of 1, content 2, col = 1, content 3 has col = 2. The content moves around so I will be updating the column number in the database via ajax. The problem is how to load all the content boxes and in the right columns. What is the best practice for doing this in Rails? Here is what I would do in PHP (psuedocode)

    // this will be content from database
    $content = $dbdata;
    // start first column
    echo '<div class="col">';
    foreach($content as $thiscontent){
        // output row divs with content
        echo '<div class="row">'.$thiscontent['body'].'</div>';
        if($lastcol == $thiscontent['col']){
             // end col and create new col div
             echo '</div><div class="col">';
        $lastcol = $thiscontent['col'];
    // ends last column
    echo '</div>';

I could just be a noob and going about this the wrong way, so feel free to educate me on how this should be done. Is my database not the way to determine col number? Does rails handle iteration differently than I suspect?

1条回答 默认 最新

相关推荐 更多相似问题