'rails generate scaffold' is adding an 's'

25 views
Skip to first unread message

gvim

unread,
May 16, 2014, 12:35:43 PM5/16/14
to rubyonra...@googlegroups.com
Using Rails 4.1.1 this command:

rails g scaffold Main home contact events about

.... generates:

app/controllers/mains_controller.rb

Why has 's' been appended? This didn't happen with 4.1.0.

gvim

Robert Walker

unread,
May 18, 2014, 12:04:36 PM5/18/14
to rubyonra...@googlegroups.com
Gerald Vim wrote in post #1146378:
Did you mean "rails g controller main home contact event about"?

If you use scaffold Rails with generate based on "Main" being a model
first then generate a controller and views based on the model name
pluralized based on inflections database.

It also seems really odd to me your choice of methods to add to your
controller. Shouldn't "home", "contact", "events" and "about" have their
own controllers with their own routes?

$ rails g controller main home contact events about
create app/controllers/main_controller.rb
route get 'main/about'
route get 'main/events'
route get 'main/contact'
route get 'main/home'
invoke erb
create app/views/main
create app/views/main/home.html.erb
create app/views/main/contact.html.erb
create app/views/main/events.html.erb
create app/views/main/about.html.erb
invoke test_unit
create test/controllers/main_controller_test.rb
invoke helper
create app/helpers/main_helper.rb
invoke test_unit
create test/helpers/main_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/main.js.coffee
invoke scss
create app/assets/stylesheets/main.css.scss

$ rake routes
Prefix Verb URI Pattern Controller#Action
main_home GET /main/home(.:format) main#home
main_contact GET /main/contact(.:format) main#contact
main_events GET /main/events(.:format) main#events
main_about GET /main/about(.:format) main#about

I suppose this would work, but still seems quite add to me.

--
Posted via http://www.ruby-forum.com/.

mike2r

unread,
May 18, 2014, 12:17:08 PM5/18/14
to rubyonra...@googlegroups.com
That's always been the case. I would recommend going through a good tutorial such as railstutorial.org to understand the basic conventions used in Rails.  The model name is usually singular, such as Main.  The controller is the pluralized version of the model name, as is the name of the table it creates in the database.  In this case, your controller name is mains and if you run rake db:migrate, the table that gets set up in the database will also be mains.   
Reply all
Reply to author
Forward
0 new messages