-
Notifications
You must be signed in to change notification settings - Fork 0
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
5a6dfd8
commit 61e2d98
Showing
19 changed files
with
379 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
class AccountsController < ApplicationController | ||
before_action :set_account, only: %i[ show edit update destroy ] | ||
|
||
# GET /accounts or /accounts.json | ||
def index | ||
@accounts = Account.all | ||
end | ||
|
||
# GET /accounts/1 or /accounts/1.json | ||
def show | ||
end | ||
|
||
# GET /accounts/new | ||
def new | ||
@account = Account.new | ||
end | ||
|
||
# GET /accounts/1/edit | ||
def edit | ||
end | ||
|
||
# POST /accounts or /accounts.json | ||
def create | ||
@account = Account.new(account_params) | ||
|
||
respond_to do |format| | ||
if @account.save | ||
format.html { redirect_to account_url(@account), notice: "Account was successfully created." } | ||
format.json { render :show, status: :created, location: @account } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
format.json { render json: @account.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PATCH/PUT /accounts/1 or /accounts/1.json | ||
def update | ||
respond_to do |format| | ||
if @account.update(account_params) | ||
format.html { redirect_to account_url(@account), notice: "Account was successfully updated." } | ||
format.json { render :show, status: :ok, location: @account } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
format.json { render json: @account.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /accounts/1 or /accounts/1.json | ||
def destroy | ||
@account.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to accounts_url, notice: "Account was successfully destroyed." } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_account | ||
@account = Account.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def account_params | ||
params.require(:account).permit(:username, :firstname, :lastname, :email, :phone, :password, :location) | ||
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,2 @@ | ||
module AccountsHelper | ||
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,2 @@ | ||
class Account < ApplicationRecord | ||
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,37 @@ | ||
<div id="<%= dom_id account %>"> | ||
<p> | ||
<strong>Username:</strong> | ||
<%= account.username %> | ||
</p> | ||
|
||
<p> | ||
<strong>Firstname:</strong> | ||
<%= account.firstname %> | ||
</p> | ||
|
||
<p> | ||
<strong>Lastname:</strong> | ||
<%= account.lastname %> | ||
</p> | ||
|
||
<p> | ||
<strong>Email:</strong> | ||
<%= account.email %> | ||
</p> | ||
|
||
<p> | ||
<strong>Phone:</strong> | ||
<%= account.phone %> | ||
</p> | ||
|
||
<p> | ||
<strong>Password:</strong> | ||
<%= account.password %> | ||
</p> | ||
|
||
<p> | ||
<strong>Location:</strong> | ||
<%= account.location %> | ||
</p> | ||
|
||
</div> |
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,2 @@ | ||
json.extract! account, :id, :username, :firstname, :lastname, :email, :phone, :password, :location, :created_at, :updated_at | ||
json.url account_url(account, format: :json) |
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,52 @@ | ||
<%= form_with(model: account) do |form| %> | ||
<% if account.errors.any? %> | ||
<div style="color: red"> | ||
<h2><%= pluralize(account.errors.count, "error") %> prohibited this account from being saved:</h2> | ||
|
||
<ul> | ||
<% account.errors.each do |error| %> | ||
<li><%= error.full_message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div> | ||
<%= form.label :username, style: "display: block" %> | ||
<%= form.text_field :username %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :firstname, style: "display: block" %> | ||
<%= form.text_field :firstname %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :lastname, style: "display: block" %> | ||
<%= form.text_field :lastname %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :email, style: "display: block" %> | ||
<%= form.text_field :email %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :phone, style: "display: block" %> | ||
<%= form.text_field :phone %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :password, style: "display: block" %> | ||
<%= form.text_field :password %> | ||
</div> | ||
|
||
<div> | ||
<%= form.label :location, style: "display: block" %> | ||
<%= form.text_field :location %> | ||
</div> | ||
|
||
<div> | ||
<%= form.submit %> | ||
</div> | ||
<% 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,10 @@ | ||
<h1>Editing account</h1> | ||
|
||
<%= render "form", account: @account %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Show this account", @account %> | | ||
<%= link_to "Back to accounts", accounts_path %> | ||
</div> |
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,14 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<h1>Accounts</h1> | ||
|
||
<div id="accounts"> | ||
<% @accounts.each do |account| %> | ||
<%= render account %> | ||
<p> | ||
<%= link_to "Show this account", account %> | ||
</p> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to "New account", new_account_path %> |
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 @@ | ||
json.array! @accounts, partial: "accounts/account", as: :account |
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,9 @@ | ||
<h1>New account</h1> | ||
|
||
<%= render "form", account: @account %> | ||
|
||
<br> | ||
|
||
<div> | ||
<%= link_to "Back to accounts", accounts_path %> | ||
</div> |
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,10 @@ | ||
<p style="color: green"><%= notice %></p> | ||
|
||
<%= render @account %> | ||
|
||
<div> | ||
<%= link_to "Edit this account", edit_account_path(@account) %> | | ||
<%= link_to "Back to accounts", accounts_path %> | ||
|
||
<%= button_to "Destroy this account", @account, method: :delete %> | ||
</div> |
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 @@ | ||
json.partial! "accounts/account", account: @account |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class CreateAccounts < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :accounts do |t| | ||
t.string :username | ||
t.string :firstname | ||
t.string :lastname | ||
t.string :email | ||
t.string :phone | ||
t.string :password | ||
t.string :location | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,48 @@ | ||
require "test_helper" | ||
|
||
class AccountsControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@account = accounts(:one) | ||
end | ||
|
||
test "should get index" do | ||
get accounts_url | ||
assert_response :success | ||
end | ||
|
||
test "should get new" do | ||
get new_account_url | ||
assert_response :success | ||
end | ||
|
||
test "should create account" do | ||
assert_difference("Account.count") do | ||
post accounts_url, params: { account: { email: @account.email, firstname: @account.firstname, lastname: @account.lastname, location: @account.location, password: @account.password, phone: @account.phone, username: @account.username } } | ||
end | ||
|
||
assert_redirected_to account_url(Account.last) | ||
end | ||
|
||
test "should show account" do | ||
get account_url(@account) | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get edit_account_url(@account) | ||
assert_response :success | ||
end | ||
|
||
test "should update account" do | ||
patch account_url(@account), params: { account: { email: @account.email, firstname: @account.firstname, lastname: @account.lastname, location: @account.location, password: @account.password, phone: @account.phone, username: @account.username } } | ||
assert_redirected_to account_url(@account) | ||
end | ||
|
||
test "should destroy account" do | ||
assert_difference("Account.count", -1) do | ||
delete account_url(@account) | ||
end | ||
|
||
assert_redirected_to accounts_url | ||
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,19 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
username: MyString | ||
firstname: MyString | ||
lastname: MyString | ||
email: MyString | ||
phone: MyString | ||
password: MyString | ||
location: MyString | ||
|
||
two: | ||
username: MyString | ||
firstname: MyString | ||
lastname: MyString | ||
email: MyString | ||
phone: MyString | ||
password: MyString | ||
location: MyString |
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,7 @@ | ||
require "test_helper" | ||
|
||
class AccountTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
Oops, something went wrong.