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 @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.

The description of the following difficult cutting works successfully, @ array [1] , @array [2] and @array [3 ] :

 To avoid the output,  @ array.each do | Key, value |   

but instead of hardcoding '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 (', ')   

This output is successfully copied to ' 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   

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.

  @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

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -