I'm in the process of refactoring some code. I'm trying to use arrays in my view as part of a for loop that makes columns in a table.
I have defined the arrays in my controller:
subjects_controller.rb
def index
...
@CRFS_TO_VIEW = [Baseline, TreatmentCompletion]
@CRF_PATH = {Baseline => 'baseline_path', TreatmentCompletion => tc_path}
end
So my goal; as the function iterates over @CRFS_TO_VIEW, the correct path is selected from @CRF_PATH and appended to the link_to function.
indext.html.erb
<% @CRFS_TO_VIEW.each do |crf| %>
<% path = @CRF_PATH[crf] %>
<%= link_to "edit", path(crf.where(subject_id: sub.subject_id).first %>
<% end %>
I also tried :
<%= link_to "edit", @CRF_PATH[crf](crf.where(subject_id: sub.subject_id).first %>
Which didn't work. I feel I must be getting close, any help or insight would be greatly appreciated.
Thanks.
@CRFS_TO_VIEWarray, shouldn't the elements be strings? like@CRFS_TO_VIEW = ['Baseline', 'TreatementCompletion']. Same with@CRF_PATH.