ruby - Pass a Rails variable into a case statement -
I am using rail and I have an array which I am trying to control output.
In short, if a project with an ID exists in The description of the following difficult cutting works successfully, but instead of hardcoding This output is successfully copied to Is there any way to use this method, or Perhaps a better way of getting it using some rail capabilities? I saw what seemed most relevant, but how it could not be implemented. You can do it like this. @projects , then I do not want to output the relative portion of that array, if it exists, If there is a project with ID, then I do not want to do the output
@array [1] , even if it exists.
@ array [1] ,
@array [2] and
@array [3 ] :
To avoid the output,
@ array.each do | Key, value |
'1', leave '# 1', '2', '3' and then # next to this array key end #, '2', ' 3 ', I really want them to be dynamically passed through the active record. I tried to create a string:
@projects_string = @ projects.map {| Element | "# {Element.id} '"} .join (', ')
' 1 ',' 2 ',' 3 '. But I can not understand a way to pass it in the case statement. It fails to match:
@ array.each do | Key, value | The case key when "# {@ projects_string}" then next # leave this array key end # Otherwise, end something else
@project_arr = @ projects.map {| P | P.id.to_s} @ array.each. Key, value | Unless @project_arr.include? (Key.to_s) # Your code goes here and end of # SKIP IT end
Comments
Post a Comment