Closed vindir closed 10 years ago
Ah, so unfortunately you can't do this. The context within the menu block is a menu instance, hence why you can call #match
seemingly on nothing. This means that the instance variable you're referencing, @pin
, is being looked up on the MenuBuilder
itself, and thus comes out as nothing at all.
My preferred solution is this:
class MyController < Adhearsion::CallController
def run
@pin = metadata[:pin]
menu t('94'), timeout: 20.seconds, tries: 2 do
match(0) do
dial_customer_care
end
match(pin) do
set_success
end
end
end
private
def pin
@pin
end
end
or if you don't really need the assignment:
class MyController < Adhearsion::CallController
def run
menu t('94'), timeout: 20.seconds, tries: 2 do
match(0) do
dial_customer_care
end
match(metadata[:pin]) do
set_success
end
end
end
end
That hash lookup is gonna be super-fast anyway, so probably not worth caching the PIN in an instance variable unless you have other cause to do so.
Not sure of cause to narrow it down.
Attempting to set a matcher from an instance variable for a PIN code.
gist: https://gist.github.com/vindir/d46e4fe75889043a8703
Code Snippet:
Resulting Grammar: