Sunday, April 3, 2011

Re: [Rails] is overriding file naming conventions (for models and controllers) possible?

On 3 April 2011 14:05, Colin Law <clanlaw@googlemail.com> wrote:
> ...
> 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.

I think it is actually String#underscore that is causing the problem
(this is called by tableize)
ruby-1.8.7-p302 > "KnownIP".underscore
=> "known_ip"

The source of this can be seen at
http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore
At the head of this file is a statement that the rules will not be
changed as this could cause existing apps to fail, which makes sense.
I do not know how to override this for special cases (or if it is
possible other than monkey patching).

My suggestion in the earlier post to manually create the model file
and call the model what you want, while using set_table_name may well
be the solution.

Colin

>
> 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate