This project is archived and is in readonly mode.
Can't have a two letter model name
Reported by Mitch | July 11th, 2008 @ 12:58 AM | in 2.x
I created a two letter model name (LP -- as in 'album') and I can't get it to work.
The model file is named 'lp.rb'
When I name the model class Lp I get the error:
Expected ...models/lp.rb to define LP
When I name the model class LP I get the error:
Expected ...models/lp.rb to define Lp
When I name the file LP.rb I don't think the file gets called.
I'm running Rails 2.1.
Comments and changes to this ticket
-
Clemens Kofler July 11th, 2008 @ 10:07 AM
- Tag changed from model naming, 2.1 to 2.1, activerecord, bug
I can't confirm this.
./script/generate scaffold lp name:string
rake db:migrate
Works fine in ./script/console:
Loading development environment (Rails 2.1.0)
>> l = Lp.find(:first)
=> #
>> exit
Also works fine with ./script/server:
Processing LpsController#index (for 127.0.0.1 at 2008-07-11 11:02:26) [GET]
Session ID: BAh7BzoMY3NyZl9pZCIlODM2ZGM2NDNmYzgxYzFhODhkYWViYzIwZWVmODAz
NDEiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
c2h7AAY6CkB1c2VkewA=--7c38f36cc0db1a43cc81d42bd5de0365f862d2f4
Parameters: {"action"=>"index", "controller"=>"lps"}
SQL (0.000211) SET NAMES 'utf8'
SQL (0.000109) SET SQL_AUTO_IS_NULL=0
Lp Load (0.000263) SELECT * FROM `lps`
Rendering template within layouts/lps
Rendering lps/index
Lp Columns (0.002606) SHOW FIELDS FROM `lps`
Completed in 0.01624 (61 reqs/sec) | Rendering: 0.00724 (44%) | DB: 0.00319 (19%) | 200 OK [http://localhost/lps]
Rails version is 2.1 - tried it both from the gem version and frozen. Also works fine with current Edge Rails.
-
RSL July 11th, 2008 @ 02:08 PM
It seems that the model generator does incorrectly name the file. :/ All the other generators seem to employ l_p.
sneaky:test rsl$ script/generate scaffold LP
exists app/models/
exists app/controllers/
exists app/helpers/
create app/views/l_ps
exists app/views/layouts/
exists test/functional/
exists test/unit/
exists public/stylesheets/
create app/views/l_ps/index.html.erb
create app/views/l_ps/show.html.erb
create app/views/l_ps/new.html.erb
create app/views/l_ps/edit.html.erb
create app/views/layouts/l_ps.html.erb
create public/stylesheets/scaffold.css
create app/controllers/l_ps_controller.rb
create test/functional/l_ps_controller_test.rb
create app/helpers/l_ps_helper.rb
route map.resources :l_ps
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/lp.rb
create test/unit/lp_test.rb
create test/fixtures/lps.yml
exists db/migrate
create db/migrate/20080711120658_create_lps.rb
On further inspection this is because Inflector.underscore looks for camelcasing and since there are no lowercase letters at all, it doesn't trigger the gsubs. Inflector's behavior makes sense and LP seems like a less than optimal choice but it does reveal an inconsistency that could be rectified without causing breakage. I think it would be better for the generators to use a localized algorithm for underscoring from camelcase like this rather than modifying how Inflector works. Sound right?
-
josh July 19th, 2008 @ 09:45 PM
- State changed from new to wontfix
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>