Justin Meltzer
Justin Meltzer

Reputation: 13558

Why is this embedded ruby code evaluating to nothing?

This code here:

<%= case event.subject.value
        when 1
            puts " upvoted"
        when -1
            puts " downvoted"
        when 0
            puts " removed a vote from"     
    end %>

does not result in any string being rendered. I tried adding an else statement just in case event.subject.value had a different value from 1, -1, or 0, but the code still evaluated to nothing. The code throws no errors...

Upvotes: 0

Views: 86

Answers (4)

Justin Meltzer
Justin Meltzer

Reputation: 13558

Ok I realized what the problem was. I had to remove the puts from the switch statement.

Upvotes: 0

sawa
sawa

Reputation: 168209

puts returns nil. It's side effect is that it outputs to the stdout.

Upvotes: 2

Vlad Khomich
Vlad Khomich

Reputation: 5880

"puts" method outputs to your console( server log ), did you try to remove puts?

Upvotes: 1

Naren Sisodiya
Naren Sisodiya

Reputation: 7288

<%= case event.subject.value
    when 1
        " upvoted"
    when -1
        " downvoted"
    when 0
        " removed a vote from"     
end %>

remove puts statement

Upvotes: 3

Related Questions