56. Contact Create Action for Saving to the Database
- We'll reach a milestone by learning how to save forms to a database, programatically.
- We'll also add a Rails flash notice to our layout file.
- Then, we'll use the rails console command to view what is inside our database.
... def new @contact = Contact.new end def create @contact = Contact.new(contact_params) if @contact.save redirect_to new_contact_path, notice: "Message sent." else redirect_to new_contact_path, notice: "Error occured." end end private def contact_params params.require(:contact).permit(:name, :email, :comments) end ...
... <%= flash[:notice] %> ...
To view what is inside our database...
rails console > Contact.all > exit
Then wrap up by saving and deploying a Git commit.
git status git add . git commit -m "Added contact create action to save to db" git push origin contact_form