我在我的应用中创建了这些控制器:
rails generate controller pages index about
后来我决定创建一个新的(不确定它是否正确)但我收到警告因为pages
已经存在:
$ rails generate controller pages contact
conflict app/controllers/pages_controller.rb
Overwrite /home/action/workspace/myapp/app/controllers/pages_controller.rb? (enter "h" for help) [Ynaqdh]
force app/controllers/pages_controller.rb
route get 'pages/contact'
invoke erb
exist app/views/pages
create app/views/pages/contact.html.erb
invoke test_unit
conflict test/controllers/pages_controller_test.rb
Overwrite /home/action/workspace/myapp/test/controllers/pages_controller_test.rb? (enter "h" for help) [Ynaqdh]
force test/controllers/pages_controller_test.rb
invoke helper
identical app/helpers/pages_helper.rb
invoke test_unit
identical test/helpers/pages_helper_test.rb
invoke assets
invoke coffee
identical app/assets/javascripts/pages.js.coffee
invoke scss
identical app/assets/stylesheets/pages.css.scss
点击后输入一切正常,但在pages_controller.rb
新网页contact
未添加:
class PagesController < ApplicationController
def index
@notice = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
end
def about
end
end
我是rails的新手,这是我的问题:这是向控制器添加新页面的正确方法吗?
我可以输入def contact
来添加它,但可能还有另一种方法。手动添加一个页面是可以的,但如果我必须添加几个,那将是一场噩梦。如果不清楚我会尝试重新说出来。感谢。
答案 0 :(得分:1)
如果你想完全更换控制器,首先要清除它是更清洁的:
~$ rails destroy controller pages
remove app/controllers/pages_controller.rb
invoke erb
remove app/views/pages
invoke test_unit
remove test/controllers/pages_controller_test.rb
invoke helper
remove app/helpers/pages_helper.rb
invoke test_unit
remove test/helpers/pages_helper_test.rb
invoke assets
invoke coffee
remove app/assets/javascripts/pages.js.coffee
invoke scss
remove app/assets/stylesheets/pages.css.scss
~$ rails generate controller pages contact
create app/controllers/pages_controller.rb
route get 'pages/contact'
invoke erb
create app/views/pages
create app/views/pages/contact.html.erb
invoke test_unit
create test/controllers/pages_controller_test.rb
invoke helper
create app/helpers/pages_helper.rb
invoke test_unit
create test/helpers/pages_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/pages.js.coffee
invoke scss
create app/assets/stylesheets/pages.css.scss