forked from turingschool-examples/little-esty-shop
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6125aa5
commit a140649
Showing
6 changed files
with
43 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
class Admin::MerchantsController < ApplicationController | ||
#reason to have 2 merchant controllers -- encapsulates methods within the Admin realm in a separate controller | ||
def index | ||
@merchants = Merchant.all | ||
end | ||
|
||
def show | ||
@merchant = Merchant.find(params[:id]) | ||
end | ||
|
||
def edit | ||
@merchant = Merchant.find(params[:id]) | ||
end | ||
|
||
def update | ||
merchant = Merchant.find(params[:id]) | ||
merchant.update(merchant_params) | ||
redirect_to "/admin/merchants/#{merchant.id}" | ||
flash[:notice] = "Successfully Updated Merchant Information" | ||
end | ||
|
||
private | ||
def merchant_params | ||
params.require(:merchant).permit(:name, :status) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= form_with model: [:admin, @merchant], local: true do |form| %> | ||
<%= form.label :name %> | ||
<%= form.text_field :name, required: :true %> | ||
<%= form.submit "Update Merchant" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<div id="merchant_show-<%=@merchant.id%>"> | ||
<p><%= @merchant.name %> | ||
</div> | ||
<div id="merchant_show-<%=@merchant.id%>"> | ||
<h1><%= @merchant.name %></h1> | ||
<p><%= link_to "Update Merchant", "/admin/merchants/#{@merchant.id}/edit" %></p> | ||
</div> | ||
|
||
<% if flash.any? %> | ||
<%= flash[:notice] %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters