0

I have a ruby on rails application that recently started giving me issues.

I believe there may be a weird bug/feature in the way rails is pluralizing model names for the database.

For example, I have a model called DiagExerciceWeekFive. The table in the database is called diag_exercice_week_fives. The pluralization works correctly here.

I think there may be a problem in the way rails is attempting to "de-pluralize" the table into the respective objects.

When I try to load up a simple form that displays all of my diagweekfives, I get this error:

uninitialized constant Diag::DiagExerciceWeekFife

Not once have I used that name in my application.

Here's the relevant bit of code that is throwing the error:

<% ExerciceWeekFive.all.each do |exercice| %>
                                    <tr class="success">
                                        <td><%= check_box_tag :exercices_week_five_ids, exercice.id, @diag.exercices_week_fives.include?(exercice), :name => 'diag[exercices_week_five_ids][]' %></td>
                                        <td><%= exercice.number %></td>
                                        <td><%= exercice.description %></td>
                                    </tr>

The exception is thrown on the first <td> within the <tr>

Has anyone run into this before? I know little about rails, but I am trying to maintain some legacy code.

Thanks.

  • I would create an instance variable in your ExerciceWeeklyFives controller `@exerciceweekfive = ExerciceWeekFive.all` then iterate through the object `@exerciceweekfiv.each` in your view. It's best practice to keep that logic in the controller – Cyzanfar Mar 29 '15 at 23:31
  • 1
    You may want to try defining an `irregular` in config/initializers/inflections.rb. [Docs.](http://api.rubyonrails.org/classes/ActiveSupport/Inflector/Inflections.html#method-i-irregular) – pdoherty926 Mar 30 '15 at 02:47

0 Answers0