Inflection wrong for words ending in 'ss'

12 views
Skip to first unread message

Paul

unread,
Apr 17, 2013, 11:57:12 AM4/17/13
to hobo...@googlegroups.com
Got the following errors while running a Hobo 2.0.0 app on Rails 3.2.12 on ruby 1.9.3-p327. The error looks to me like it is a problem with Rails or Hobo.

I found a solution to the problem as described below. 

Example that caused the problem to surface
Created two models, MyClass and MySubClass where MyClass has_many :my_sub_classes. And, not that I think it matters, these controllers belong to the admin subsite.

All working fine until I added an :index page for MySubClass to MyClass.

my_sub_classes_controller.rb
auto_actions_for : my_classes, [:index]

Error occured when I requested localhost:3000/my_classes/1/my_sub_classes
Couldn't find MyClass without an ID
Request

Parameters:

{"my_clas_id"=>"1"}


Using rails console I was able to confirm by executing 'my_class'.singularize => 'my_clas'
At the same time, 'my_classes'.singularize => 'my_class'

My Solution
I was able to correct the problem by adding the following to config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.singular /^([a-z_\-]+ss)$/i, '\1'
end

Looking forward to feedback.

Best,
 Paul

Bryan Larsen

unread,
Apr 17, 2013, 12:12:15 PM4/17/13
to hobo...@googlegroups.com
The Rails pluralizer is designed to cover 99% of use cases, but not
100%. It's impossible to reach 100%; they've stopped accepting
patches for the pluralizer.

The usual solution is to do something like:

has_many :my_sub_classes, :class_name => "MySubClass"

What's interesting about your test case is that it appears to being
run through the singularization twice. my_sub_classes ->
my_sub_class -> my_sub_clas

That might indicate a bug in Hobo somewhere.

Bryan
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to hobousers+...@googlegroups.com.
> To post to this group, send email to hobo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/hobousers?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Paul

unread,
Apr 17, 2013, 12:43:24 PM4/17/13
to hobo...@googlegroups.com
Thank you Bryan for the clarification. Makes sense as the English language is not so simple.

I did add the :class_name to both the has_many and belongs_to statements in the respective models. Unfortunately, the problem remains unless I add the new inflection rule.

Best,
 Paul
Reply all
Reply to author
Forward
0 new messages