1

I initialize array

k = Array.new

then something like

@m = Modul.where(:rfp_id => @rfp.id)
i = 0
for ii in @m
  k = ii.name.to_s
  i = i + 1
end 

and then

 k.each do |a|
    ...
 end

but value is not stored in "k" how can i do this?

2 Answers 2

3

Try write clean code, for example:

Modul.where(:rfp_id => @rfp.id).pluck(:name).each do |name|
  puts name
end
Sign up to request clarification or add additional context in comments.

Comments

1

Change this k = ii.name.to_s to k.push(ii.name.to_s). It will work. You did not anywhere add the item ii.name.to_s to your array k. k = ii.name.to_s means in each loop iteration, you are going to reference a new string object to the local variable k. Read Array#push to get introduce yourself to the method.

Don't need to write k = Array.new, ratherk = [] is enough for your purpose.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.