
Put the index action and all the other standard controller actions above the private methods we created earlier. Create the index method and add the following code to get all of the active authors in alphabetical order and assign it to Note we are also using the will_paginate gem to prepare the returned data for pagination: = Author. Now we will create our standard RESTful actions in the controller: index, show, new, edit, create, update and destroy. Now create this private method below the author_params method we created earlier with this code: def set_author = Author.

This will run the set_author method prior to each of the show, edit, update and destroy actions. Put the following code at the top of (but still inside) the class definition: before_action :set_author, only: We want to create this author and assign it to an object before starting each of these methods. When we work with show, edit, update and destroy actions, we will be working with a particular author based on an author_id provided by the user via our interface. Note we make this a private method so that it can only be called by other methods within the class.

permit ( :first_name, :last_name, :active ) end Open the authors_controller.rb file inside of app/controllers and within the class definition, add the following code to restrict the types of parameters we will accept from users.

The first thing to do is to build a controller for authors. (There are no controllers yet for authors and categories, so limit yourself to books for now.) Start the server and verify that the basic app is running by looking at the various book lists. Run the rails db:migrate command to generate the development database and then run rails db:populate to add records to your development database. Checkout to a new branch named views_controllers. Run git branch to see that you are on the master branch.

Run bundle install from the terminal to install the new gems used in this project. To get a copy of this new project, use git to clone the BookManager_3 project on github and review the contents before proceeding. For this project we are using another version of the BookManager application we've developed previously.
