singular_route_key snippets

Namespaced singular routes for uncountables in Rails

Tagged namespace, singular_route_key  Languages ruby

Correct(ing) singular route for an uncountable namespaced model in Rails:

Problem:

$ rails console
> Namespace::SMS.model_name.singular_route_key => namespace_sm
> app.polymorphic_path(Namespace::SMS.first) => NoMethodError namespace_sm_path

Solution:

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.uncountable %w(namespace_sms)
end

Voila:

$ rails console
> Namespace::SMS.model_name.singular_route_key => namespace_sms