douze2890241475 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条回答 默认 最新


      相关推荐 更多相似问题


      • ¥20 有人知道怎么将vsi格式的图片文件,转换为svs格式的文件吗
      • ¥15 历史模拟法计算var实验报告
      • ¥15 白鲸算法优化K值的VMD分解出错
      • ¥20 写一个基于52单片机用hc-05蓝牙模块控制28BYJ-48步进电机进行旋转,在手机蓝牙串口输入1019电机转半圈,输入2038电机转一圈,输入0复位的代码吗
      • ¥15 求51单片机8位数码管计时器程序
      • ¥20 matlab识别螺母边缘
      • ¥15 python 6x6游戏加登录、记录系统
      • ¥100 基于做一个模拟智慧路灯
      • ¥15 ME21N 创建采购成功并且生成采购订单号,但显示“快件文档更新已取消”,SM13看错误提示为如下截图:
      • ¥30 android 集成fmod实现变声功能中遇到的问题