Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Edit Manufacturer #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/controllers/manufacturers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ def create
end
end

def edit
@manufacturer = Manufacturer.find(params[:id])
end

def update
@manufacturer = Manufacturer.find(params[:id])

if @manufacturer.update(manufacturer_update_params)
redirect_to edit_manufacturer_path(@manufacturer), notice: "Manufacturer updated successfully!"
else
redirect_to edit_manufacturer_path(@manufacturer), error: "Error updating manufacturer."
end
end

def destroy
@manufacturer = Manufacturer.find(params[:id])
@manufacturer.destroy
Expand All @@ -32,5 +46,13 @@ def destroy
def manufacturer_params
params.require(:manufacturer).permit(:username, :password, :name, :email, :telephone)
end

def manufacturer_update_params
params.require(:manufacturer).permit(:email, :telephone)
end

def manufacturer_update_params
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the function defined two times?

Copy link
Collaborator Author

@jaredfitton jaredfitton Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shereenElSayed because when updating we only want to update a users email or telephone.

params.require(:manufacturer).permit(:email, :telephone)
end

end