ruby on rails - DRYing out the path.rb -


i'm new cucumber, , i'd ask how dry out code (which not contain errors):

when /^the user page$/   users_path  when /^the review page$/   reviews_path 

i tried use regexp like

when /^the (.+) page$/   $1.to_s+'s_path' 

but apparently wrong. in advance!

solution (based on answer aledalgrande):

when /^the (.+) page$/   send("#{$1}s_path") 

this should work:

when /^the "(.+)" page$/ |destination|   send("#{destination}s_path") end 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -