keyan.r keyan.r - 5 months ago 33
Ruby Question

Implementing .each in Wicegrid (Ruby on Rails)

I have the following column in my Wicegrid table, which iterates through the advisors of a student and lists them in the Wicegrid:

g.column name: 'Student Advisor' do |user|
res=''
if user.advisors
user.advisors.each do |advisor|
advisor.username
end
end
end


Wicegrid doesn't allow arrays to be returned inside their columns or at least that is what I understood from the error below:

"When WiceGrid column block returns an array its second element is expected to be a hash containing HTML attributes for the tag."

Is there another way to have the list of advisors in the table?

Answer

If I understood the requirements properly, the following will return a list of advisors, if exists, concatenated with commas:

g.column name: 'Student Advisor' do |user|
  user.advisors.map(&:username).join(', ') if user.advisors
end
Comments