Search code examples
ruby-on-railsrubymongodbmongoiddynamic-attributes

Rails / MongoDB: Variable to address object-attribute not translating


In my class AleShot I have some dynamic mongoid-attributes. In order to index them, I collect all attributes in an array called "dynamos". Now when I want to list these (see code below) I get: undefined method 'dyn_f' for #<AleShot:0x007f8f7ab18328> Any Ideas why the dyn_f-variable isn't translated correctly?

<% @ale_shots.each do |ale_shot| %>
  <tr>
    <td><%= ale_shot.name %></td>
    <% dynamos.each do |dyn_f| %>
        <td><%= ale_shot.dyn_f %></td>
    <% end %>
  </tr>
<% end %>

Solution

  • That could be because dyn_f is not defined as a field in the model.

    Access it like this

    ale_shot['dyn_f']