On 3 April 2011 13:54, Colin Law <[email protected]> wrote:
> On 3 April 2011 13:25, Michael Pavling <[email protected]> wrote:
>> On 2 April 2011 23:50, Alexey Muranov <[email protected]> wrote:
>>> Hello, i have another question about overriding Rails conventions.
>>>
>>> Is it possible to tell Rails which model/controller is defined in which
>>> file?
>>>
>>> I have generated a model and a controller as follows:
>>>
>>> $ rails generate model KnownIP ...
>>> ...
>>> $ rails generate controller KnownIPs ...
>>>
>>> The problem is with the "IP" in the name: now i have a model *KnownIp*
>>> in the file *known_ip.rb* and a controller *KnownIPsController* in the
>>> file *known_i_ps_controller.rb*, which does not look consistent.
>>
>> Something's wrong with your typing here or on the console, because
>> your model should be "KnownIP" if you typed "$ rails generate model
>> KnownIP". If the "p" is lower case in the model, you must have typed a
>> lower case p...
>
> Actually Alexey is right, using rails 3.0.5 then
> rails g model KnownIP
> generates models/known_ip and class KnownIp
>
> Also
> rails g model ABCdEF
> gives ab_cd_ef.rb and class AbCdEf
> and
> rails g model ABCDEFG
> gives abcdefg.rb and class Abcdefg
>
> all rather odd.

It appears that this may be the technique rails uses, first to get the
table name from the model in the generate command String#tableize is
used, then singularize is used on this to get the file name, and then
camelize to get the class name, so

ruby-1.8.7-p302 > "KnownIP".tableize
 => "known_ips"
ruby-1.8.7-p302 > "KnownIP".tableize.singularize.camelize
 => "KnownIp"

Since tableize uses ActiveSupport::Inflector.tableize it may be
possible to override this for particular cases.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to