I am trying to submit information into a PHP database and I am getting this error.
authors_controller.rb
class AuthorsController < ApplicationController
def new
@page_title = 'Add New Author'
@author = Author.new
end
def create
@author = Author.new(author_params)
@author.save
redirect_to authors_path
end
def update
end
def edit
end
def destroy
end
def index
end
def show
end
def author_params
params.require(author).permit(:first_name, :last_name)
end
end
when I click on submit button the error pops up.
undefined local variable or method `author' for AuthorsController
The error is in your author_params
where you have author
which is treated as undefined variable. It should be :author
(a symbol)
def author_params
params.require(:author).permit(:first_name, :last_name)
end