Reputation:
I have my controller
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
And my archive .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>
How make for the code name: <%= raw @mapa[:descricao] %>
,
receive the controller value mapa[:descricao] = a.descricao
,
I just show the value in variable name, replacing <%= raw @mapa[:descricao] %>
understood? Thanks!!
Upvotes: 2
Views: 167
Reputation: 7225
try this out
first of all turn mapa into instance variable(@mapa)
and then update js.erb file accordingly as given below.
<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[:tasks][0][:descricao] %>',
values: [{
from: today_friendly,
to: next_friendly,
label:"Teste",
customClass: "ganttRed"
}]
}],
});
});
</script>
Upvotes: 1
Reputation: 5105
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 respond_to do |format| format.js end end
on your view:
<%= @mapa[:task].first[:descricao] %>
Upvotes: 0