Ian Ellis Ian Ellis - 1 month ago 5x
Ruby Question

Ruby on Rails: Hash not working, or in the wrong place

I'm trying to create hash values to use in a for loop in my view. But for some reason, creating these hash's pretty much breaks the whole site, no matter where I put them.

CRF_PATH = {Baseline => baseline_path, FollowUp3Week => follow_up3_week_path, TreatmentCompletion => treatment_completion_path, FollowUp18Week => follow_up18_week_path, FollowUp6Month => follow_up6_month_path, PsychosocialScale => psychosocial_scale_path}

Where should I define this hash, and am I defining it incorrectly?

Thank you for your time.


Here is what I'm trying to make work:

<% CRFS_TO_VIEW.each do |crf| %>
<% if crf.where(subject_id: sub.subject_id).first != nil %>
<% path = CRF_PATH[crf] %>
<% status = CRF_PATH[crf] %>
<% if crf.where(subject_id: sub.subject_id).first.status == 1 %>
<td bgcolor="#98FB98" >
<% else %>
<% end %>
<%= link_to "edit", path(crf.where(subject_id: sub.subject_id).first) %>
<% end %>
<% end %>

I know its a bit rough, I just hope that my goal can be seen a little easier with this. Let me know and I can clarify anything.

mwp mwp

Let's take a quick peek at the start of the hash definition:

CRF_PATH = {Baseline => baseline_path

Baseline is being evaluated as a class name. Do you have a class named Baseline? If not, what do you intend this key to be? A string, a symbol, something else?

baseline_path is being evaluated as a local variable or a method name. Do you have a method named baseline_path? If not, what do you intend this key to be? A string, a symbol, or something else?