ruby-on-railssql-serverruby-on-rails-4inflector

Rails irregular Inflector errors with routing and tablename


I need a Genus model, which should pluralize to genera. I'm using Rails 4.2.1 with Ruby 2.2.1 and SQLServer 2014. I added an Inflector in config/initializers/inflections.rb:

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.irregular 'genus', 'genera'
end

per this question. I checked in the Rails console and it correctly singularized and pluralized, and when I ran

rails generate scaffold Genus name:string

the table name was correctly called genera, and it looked like things were correct.

However when I try to actually go to the views, I get errors. For the index page (http://0.0.0.0:3000/genera) I'm getting an error from the database as it's trying to access a table named genus:

TinyTds::Error: Invalid object name 'genus'.: EXEC sp_executesql N'SELECT [genus].* FROM [genus]'
Extracted source (around line #14):
12
13  <tbody>
14    <% @genera.each do |genus| %>
15      <tr>
16        <td><%= genus.name %></td>
17        <td><%= link_to 'Show', genus %></td>

For the new (http://0.0.0.0:3000/genera/new), I get a path error:

undefined method `genus_index_path' for #<#<Class:0x007fd9b9604380>:0x007fd993e8a2f0>
Extracted source (around line #1):                 
1 <%= form_for(@genus) do |f| %>
2   <% if @genus.errors.any? %>
3     <div id="error_explanation">
4       <h2><%= pluralize(@genus.errors.count, "error") %> prohibited this genus from being saved:</h2>
5 
6       <ul>

Trace of template inclusion: app/views/genera/new.html.erb

I'm clearly doing something wrong, but I can't find anything searching for errors like this. Do I need to do something else besides just adding that Inflector? At first I thought it was somehow SQLServer's fault, but that wouldn't effect the routing in the new view, would it?


Solution

  • The problem turns out to be that I forgot to restart my web server. Apparently changes to the Inflectors don't get picked up by the web server, but of course just running rails generate from the command line it did see the changes, so... Stupid mistake, but if anybody else happens upon it, hope this will help them.