Victor
Victor

Reputation: 13378

Putting hashes in view

I try to generate this path tag based on the type in my view:

<%= nearby_#{@nearby_type}_shop_path %>

But the # sign commented out the rest of the text. Any solution?

Thank you.

Upvotes: 1

Views: 31

Answers (2)

Peter Brown
Peter Brown

Reputation: 51697

You'll want to use send to actually execute the code.

<%= send("nearby_#{@nearby_type}_shop_path") %>

Upvotes: 3

Larry K
Larry K

Reputation: 49104

<%= "nearby_#{@nearby_type}_shop_path" %>

or

nearby_<%= @nearby_type %>_shop_path

Upvotes: -1

Related Questions