2

私は自分のコントローラーを持っています

def grafico_gantt 
    mapa = Hash.new
    mapa[:tasks] = [] 
    @projeto.atividades.each do |a|
        mapa[:tasks] << {
           id:a.id,
           descricao:a.descricao,
           status:a.status,
           data_inicial:a.data_inicial,
           tempo_gasto:a.tempo_gasto.to_i,
           data_final:a.data_final
        }
    end
end

そして私のアーカイブ .js.erb

<script>
 $(function() {
      var today = moment();
      var andTwoHours = moment().add("hours",2);
      var today_friendly = "/Date(" + today.valueOf() + ")/";
      var next_friendly = "/Date(" + andTwoHours.valueOf() + ")/";
      var maxDate = moment().add("days",10).toDate();

      $(".gantt").gantt({
        source: [{
            name: <%= raw @mapa[:descricao] %>,
            values: [{
                from: today_friendly,
                to: next_friendly,
                label:"Teste", 
                customClass: "ganttRed"
            }]

                }],

          });

    });

</script>

コード名の作り方: <%= raw @mapa[:descricao] %>、コントローラの値を受け取るmapa[:descricao] = a.descricao

変数名の値を表示するだけで、置き換えます<%= raw @mapa[:descricao] %>

了解した?ありがとう!!

4

2 に答える 2