Rails Controller
Create basic controller
rails g controller name method
Only controller name
rails generate controller
name is controller name.
If you want to associate it with model, add s.
Example
rails generate controller items
Even if create controller from command, routing is not set by default.
Remove controller
To delete controller, to delete controller files in rails.
But, rails prepares command for it
rails destroy controller name
Add controller to routes.rb as resouces
Route file is in config/routes.rb
ApplicationName::Application.routes.draw do resources :items end
In this way, there are no action in controller.
items#index We can make basic RESTful.
Also, you need to add view by yourself.
Create Controller with Actions
Example
rails generate controller items new show
new, show is action name
In that case , view is also generated
app/views/items/new.html.erb, app/views/items/show.html.erb
class ItemssController < ApplicationController def new end def show end end [/ruby] Access http://localhost:3000/items/new -> new action and go new.html.erb