Reputation: 503
I need to replace X_VARIABLE in 2 places. For the first X_VARIABLE I want to keep the text 'remove' For the second X_VARIABLE I want to keep 'd_cars_path'
<% @cars.each do |x| %>
<% @a = @b.send(x) %>
<% if @a == true %>
<%= button_to "removeX_VARIABLE", X_VARIABLEd_cars_path(:id => @user.id), class: "btn btn-large btn-primary" %>
<% end %>
<% end %>
I am looking for some help with the variable substitution syntax. Thanks.
Upvotes: 0
Views: 171
Reputation: 67900
I'd write:
<% @cars.each do |x| %>
<% if @b.send(x) %>
<%= button_to "remove#{x}",
send(:"#{x}d_cars_path", id: @user.id),
class: "btn btn-large btn-primary" %>
<% end %>
<% end %>
Upvotes: 1