开发者

Ruby on rails form_for and uncountable models

<% form_for(@software) do |f| %>

is producing a form tag that looks like this:

<form action="/software.%23%3Csoftware:0x24b2eac%3E" ...

The software model is a bit special, in that I've made it uncountable (softwares didn't sit well with me)

environment.rb:
ActiveSupport::Inflector.inflections do |inflect|
  inflect.uncountable %w( software )
end

but I did name a singular form to get the routes working

map.resources :software, :singular => :software_item

Modifying form_for like so:

<% form_for(@software, :url => software_item_path) do |f| %>

produces the correct output, so perhaps I'm going about th开发者_JS百科e whole uncountable thing the wrong way? Is there generally a better way use models with the same singular and plural word?


I know this question is quite old but I had a similar issue on Rails 4.1. According to the Inflection doc, inflect.uncountable should define:

[...] uncountable words that shouldn't be attempted inflected.

This however is insufficient for some reason (I'll dive in the source and have a look and see what's going on once I have time)

Anyway, using inflect.irregular instead of inflect.uncountable in config/initializers/inflections.rb seems to do the trick

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.irregular 'software', 'software'
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜