Muky
Muky

Reputation: 4134

javascript loop over ruby database object

I am trying to go over all builds objects in project (has_many relation) and set yy to be the last updated_at one with status 'completed'

The following javascript command which reside in my haml file:

var yy = #{project.builds.select{|b| b.status == 'completed'}.last.try(:updated_at)};

throw " Uncaught SyntaxError: Unexpected number" (although, I see in debug mode that it managed to get the correct value)

what is the correct way to go over my builds from javascript?

Upvotes: 1

Views: 77

Answers (1)

Rustam Gasanov
Rustam Gasanov

Reputation: 15791

I guess you need quotes here:

var yy = "#{ project.builds.select{|b| b.status == 'completed'}.last.try(:updated_at) }";

Upvotes: 1

Related Questions