07. Controllers - max-borisov/ihub-bookshelf GitHub Wiki
We have models and database filled in with data, so it's time to generate controllers which are glue between models and views.
$ rails generate controller books index new create show edit update destroy
Where books - controller name and other - controller actions.
app/controllers/books_controller.rb
class BooksController < ApplicationController
def index
end
def new
end
def create
end
def show
end
def edit
end
def update
end
def destroy
end
end
$ rails generate controller users show destroy
app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
end
def destroy
end
end
$ rails generate controller reviews create destroy
app/controllers/reviews_controller.rb
class ReviewsController < ApplicationController
def create
end
def destroy
end
end
$ rails generate controller shopping_cart_items index create destroy
app/controllers/shopping_cart_items_controller.rb
class ShoppingCartItemsController < ApplicationController
def index
end
def create
end
def destroy
end
end
$ rails generate controller orders index create
app/controllers/orders_controller.rb
class OrdersController < ApplicationController
def index
end
def create
end
end
For each controller rails created views, assets files and helpers.
app/views folder:
app/assets folder:
app/helpers folder: