1

I have the following loop

:javascript
$(document).ready(function() {
    $('#calendar').fullCalendar({
      defaultDate: '2014-09-12',
      editable: false,
      eventLimit: true, 
      events: [
        {
          - @kid.availabilities.order("availability_date desc").each do |availability|
            title: "#{@kid.name}",
            start: "#{availability.availability_date.to_datetime}"
        }        
      ]
    });
  });

but in the line

start: "#{availability.availability_date.to_datetime}"

I always get

NameError at /profile/jean_oso
undefined local variable or method `availability' for #<#<Class:0x007f9210786578>:0x007f92107cf750>

how can I inject this value on my javascript.

Thanks in advance.

UPDATE


I checked my developer tools and I found that

- @kid.availabilities.order("availability_date desc").each do |availability|

is printing as a text, so when I try to do this:

start: "#{availability.availability_date.to_datetime}"

the availability variable does not exist.

What I'm doing wrong????

Thanks for your help

UPDATE 2


I hate haml, I would no use again on my next project. This is how I solve my problem.

%script(type="text/javascript")
  $(document).ready(function(){
  $('#calendar').fullCalendar({
  defaultView: 'agendaWeek',
  editable: false,
  eventLimit: true,
  events: [
  - @kid.availabilities.order("availability_date desc").each do |availability|
    {
    title: "Available",
    start: "#{availability.availability_date.to_datetime.strftime("%Y-%m-%dT%H:%M:%S")}",
    end:   "#{availability.end_availability_date.to_datetime.strftime("%Y-%m-%dT%H:%M:%S")}",
    url: "#"
    },
  ],
  timeFormat: 'H(:mm)'
  });
  });
Jean
  • 5,201
  • 11
  • 51
  • 87
  • @Amadan It is passed into the `do` block. – Substantial Sep 08 '14 at 08:37
  • Sorry I'm new on rails and I don't understand what do you mean with "Did you provide availability in the locals hash? " – Jean Sep 08 '14 at 08:37
  • @Substantial: ack, didn't see. – Amadan Sep 08 '14 at 08:37
  • 1
    Please post the full error message. – Substantial Sep 08 '14 at 08:38
  • This is the full error message: NameError at /profile/jean_oso undefined local variable or method `availability' for #<#:0x007f92107cf750> – Jean Sep 08 '14 at 08:39
  • are you sure about the haml indentation there? `start: #{}` block should be indented to get parsed correclty ! – Nimir Sep 08 '14 at 08:47
  • @Nimir, yes totally agreed with you, but I think my indentation it's ok – Jean Sep 08 '14 at 08:50
  • @Jean Please post your solution as an answer to this question. Much easier to read than listing updates in the question itself. Also, please edit the question to remove the updates, and just post the gist of it all. (Especially since no one has posted an answer yet.) – onebree Jul 13 '15 at 17:06

1 Answers1

0

This is how I solve it

%script(type="text/javascript")

$(document).ready(function(){ $('#calendar').fullCalendar({ defaultView: 'agendaWeek', editable: false, eventLimit: true, events: [ - @kid.availabilities.order("availability_date desc").each do |availability| { title: "Available", start: "#{availability.availability_date.to_datetime.strftime("%Y-%m-%dT%H:%M:%S")}", end: "#{availability.end_availability_date.to_datetime.strftime("%Y-%m-%dT%H:%M:%S")}", url: "#" }, ], timeFormat: 'H(:mm)' }); });

Jean
  • 5,201
  • 11
  • 51
  • 87