ruby on rails - How to use local variables when calling show on an object i.e. @object.this_#{variable}? -
this question has answer here:
- how turn string method call? [duplicate] 3 answers
is there way pass variable through instance in show partial? i'm creating service follows crud , want able iterate instanced variable. can create passing partial so:
in parent view:
<%= form_for(@report) |f| %> <%= render :partial => "reports/forms/partial_form", :locals => {:g => f, :var => "01"} %> <% end %>
in partial view:
<label><%= "enter data variable #{lane_number}" %></label> <%= g.text_field :"variable_#{var}" %>
this useful variables in partial have similar-enough naming convention use same var
iterate through several items. works fine.
i similar when viewing input data, can't figure out how pass var
instance variable.
in parent view:
<%= render :partial => "reports/shows/partial_show", :locals => {:var => "01"} %>
in partial view:
<%= @report.variable_#{var} %>
i know #{var}
used string interpolation (which why works in original create), there way me passing variable partial?
you can use metaprogramming variable value because call method:
<%= @report.send("variable_#{var}") %>
Comments
Post a Comment