0

I'm facing an issue with ruby because I'm trying to get a nested attribute like that:

row :ratings do |ratings|
        table_for ratings.list do
          column :promptness do |list|
            table_for rating.list.promptness do
              column :rating
              column :comment
            end
          end
        end
end

I can get the data with the dot notation but I can't make it work using the [] notation like this:

['a', 'b', 'c'].each do |el|
          table_for ratings.list do
            column el do |list|
              table_for rating.list[el] do
                column :rating
                column :comment
              end
            end
          end
      end

What's the reason in this? How could I eventually solve this? Thank you for any help

willia_am
  • 188
  • 7
  • In Javascript the dot and hash notation are the same. But not in Ruby. Only for certain cases (open struct for example) are they interchangable. – max pleaner Jan 07 '17 at 00:14
  • @maxple Alright, thanks for your answer. What would be the best solution in my case then? Any idea? – willia_am Jan 09 '17 at 06:15

1 Answers1

1

What you have here:

table_for rating.list[el] do

won't work, like you know, because list doesn't respond to [].

Instead, you can do this, since el is a symbol:

table_for rating.list.send(el) do

See What does send() do in Ruby?

Community
  • 1
  • 1
max pleaner
  • 26,189
  • 9
  • 66
  • 118