-1

I have this code:

def show_block_path
  Rails.application.routes.url_helpers.gate_path(resource_id))
end

I'm trying have to refactor it:

def show_block_path
  Rails.application.routes.url_helpers."{resource_type.downcase}"_path(resource_id))
end

resource_type.downcase is "gate", but the method doesn't work. Why?

sawa
  • 160,959
  • 41
  • 265
  • 366
Roberto Pezzali
  • 2,320
  • 1
  • 25
  • 44

1 Answers1

4

Use Object#public_send:

def show_block_path
  Rails.application.routes.url_helpers.public_send(
    "#{resource_type.downcase}_path", resource_id
  )
end
Aleksei Matiushkin
  • 113,340
  • 9
  • 96
  • 151