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... > The model can be renamed without problems to KnownIP. > However, if the controller file is renamed to known_ips_controller.rb it > (most likely) will stop working What do you mean "stop working"? The controller is still the controller, whether it is handling routes for "/known_i_p" or "/known_ip"... > Another interesting example: if a model is generated with > $ rails generate model known_i_p ... > then it is broken from the beginning. Well yes, the name of the model should be the correctly cased name of the model... "known_i_p" is not... > To make it work, it is necessary to rename its file from *known_i_p.rb* > to > *known_ip.rb*, and to add > set_table_name 'known_i_ps' > to it. > Can the correspondence between file names and model names be specified > manually in such odd cases? I think the problem is you haven't actually said what you want to *do*. I don't know what "odd case" this shows. Do you mean you want to have a model called "KnownIp" but a table called "known_i_ps"? If so, why? What reason do you have for not having the table called "known_ips"? Or do you want your model called "KnownIP" but the model file called "known_ip.rb"? Again, what on earth for? What difference does the model's file name make in the scheme of things? The controller is a totally different issue - you can call a controller anything you like, it's not a 1:1 mapping to a model. -- 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.

