这是代码和愚蠢的下划线。 我正在使用rails 4
rails generate scaffold USER ip:string{20} nickname:string{100} visitnum:integer
invoke active_record
create db/migrate/20141015211014_create_users.rb
create app/models/user.rb
invoke test_unit
create test/models/user_test.rb
create test/fixtures/users.yml
invoke resource_route
route resources :users
invoke scaffold_controller
create app/controllers/use_rs_controller.rb
invoke erb
create app/views/use_rs
create app/views/use_rs/index.html.erb
create app/views/use_rs/edit.html.erb
create app/views/use_rs/show.html.erb
create app/views/use_rs/new.html.erb
create app/views/use_rs/_form.html.erb
invoke test_unit
create test/controllers/use_rs_controller_test.rb
invoke helper
create app/helpers/use_rs_helper.rb
invoke test_unit
create test/helpers/use_rs_helper_test.rb
invoke jbuilder
create app/views/use_rs/index.json.jbuilder
create app/views/use_rs/show.json.jbuilder
invoke assets
invoke coffee
create app/assets/javascripts/use_rs.js.coffee
invoke scss
create app/assets/stylesheets/use_rs.css.scss
invoke scss
identical app/assets/stylesheets/scaffolds.css.scss
为什么用户成为use_rs?这对我的工作来说看起来很愚蠢而且非常麻烦
答案 0 :(得分:2)
这是因为生成名称Rails首先在pluralize
上调用"USER"
,导致"USERs"
(注意案例),然后在生成各种名称时调用underscore
。 "USERs".underscore = "use_rs"
。改为运行以下命令(小写为user
):
rails generate scaffold user ip:string{20} nickname:string{100} visitnum:integer