-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
  • 165,429
  • 45
  • 277
  • 381
Roberto Pezzali
  • 2,484
  • 2
  • 27
  • 56

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
  • 119,336
  • 10
  • 100
  • 160