Clockコントローラーでnowというアクションを作りたかったのに、、
間違えてnewっていうアクションを作ってしまいました。。
$ rails g controller clock new
create app/controllers/clock_controller.rb
route get "clock/new"
invoke erb
create app/views/clock
create app/views/clock/new.html.erb
invoke test_unit
create test/functional/clock_controller_test.rb
invoke helper
create app/helpers/clock_helper.rb
invoke test_unit
create test/unit/helpers/clock_helper_test.rb
そんな時はrailsコマンドのdestoryで↓のように削除します。
ちゃんとrouteも削除してくれます。
$ rails destroy controller clock new
remove app/controllers/clock_controller.rb
route get "clock/new"
invoke erb
remove app/views/clock
remove app/views/clock/new.html.erb
invoke test_unit
remove test/functional/clock_controller_test.rb
invoke helper
remove app/helpers/clock_helper.rb
invoke test_unit
remove test/unit/helpers/clock_helper_test.rb
気をとりなおして、nowでもっかい作って事無きをえます。
$ rails g controller clock now
create app/controllers/clock_controller.rb
route get "clock/now"
invoke erb
create app/views/clock
create app/views/clock/now.html.erb
invoke test_unit
create test/functional/clock_controller_test.rb
invoke helper
create app/helpers/clock_helper.rb
invoke test_unit
create test/unit/helpers/clock_helper_test.rb
ちなみにrailsコマンドの短縮は
generate:g /console:c /server:s /dbconsole:db だけで、
destroyが”d”とかっていうのはありません。
$ rails d controller clock now
Error: Command not recognized
Usage: rails COMMAND [ARGS]
The most common rails commands are:
generate Generate new code (short-cut alias: "g")
console Start the Rails console (short-cut alias: "c")
server Start the Rails server (short-cut alias: "s")
dbconsole Start a console for the database specified in config/database.yml
(short-cut alias: "db")
new Create a new Rails application. "rails new my_app" creates a
new application called MyApp in "./my_app"
In addition to those, there are:
application Generate the Rails application code
destroy Undo code generated with "generate"
benchmarker See how fast a piece of code runs
profiler Get profile information from a piece of code
plugin Install a plugin
runner Run a piece of code in the application environment
All commands can be run with -h for more information.
ちなみにモデルでも同様です。
$ rails g model task name:string description:text due_date:date done:bookean
invoke active_record
create db/migrate/20110215050352_create_tasks.rb
create app/models/task.rb
invoke test_unit
create test/unit/task_test.rb
create test/fixtures/tasks.yml
$ rails destroy model task
invoke active_record
remove db/migrate/20110215050352_create_tasks.rb
remove app/models/task.rb
invoke test_unit
remove test/unit/task_test.rb
remove test/fixtures/tasks.yml
Beginning Rails 3 (Expert’s Voice in Web Development)
posted with amazlet at 11.02.15
Cloves, Jr. Carneiro Rida Al Barazi
Apress
売り上げランキング: 72391
Apress
売り上げランキング: 72391



コメント
[…] ②rails g controller でコントローラー名を間違えた! ↓ rails destroy controller で削除 参考:shinodogg.com […]