diff --git a/app/assets/stylesheets/friends.scss b/app/assets/stylesheets/friends.scss new file mode 100644 index 0000000..44c2b0a --- /dev/null +++ b/app/assets/stylesheets/friends.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the friends controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ diff --git a/app/controllers/friends_controller.rb b/app/controllers/friends_controller.rb new file mode 100644 index 0000000..354a8d6 --- /dev/null +++ b/app/controllers/friends_controller.rb @@ -0,0 +1,74 @@ +class FriendsController < ApplicationController + before_action :set_friend, only: [:show, :edit, :update, :destroy] + + # GET /friends + # GET /friends.json + def index + @friends = Friend.all + end + + # GET /friends/1 + # GET /friends/1.json + def show + end + + # GET /friends/new + def new + @friend = Friend.new + end + + # GET /friends/1/edit + def edit + end + + # POST /friends + # POST /friends.json + def create + @friend = Friend.new(friend_params) + + respond_to do |format| + if @friend.save + format.html { redirect_to @friend, notice: 'Friend was successfully created.' } + format.json { render :show, status: :created, location: @friend } + else + format.html { render :new } + format.json { render json: @friend.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /friends/1 + # PATCH/PUT /friends/1.json + def update + respond_to do |format| + if @friend.update(friend_params) + format.html { redirect_to @friend, notice: 'Friend was successfully updated.' } + format.json { render :show, status: :ok, location: @friend } + else + format.html { render :edit } + format.json { render json: @friend.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /friends/1 + # DELETE /friends/1.json + def destroy + @friend.destroy + respond_to do |format| + format.html { redirect_to friends_url, notice: 'Friend was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_friend + @friend = Friend.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def friend_params + params.require(:friend).permit(:first_name, :last_name, :email, :phone, :twitter) + end +end diff --git a/app/helpers/friends_helper.rb b/app/helpers/friends_helper.rb new file mode 100644 index 0000000..0b69e9b --- /dev/null +++ b/app/helpers/friends_helper.rb @@ -0,0 +1,2 @@ +module FriendsHelper +end diff --git a/app/models/friend.rb b/app/models/friend.rb new file mode 100644 index 0000000..863a36a --- /dev/null +++ b/app/models/friend.rb @@ -0,0 +1,2 @@ +class Friend < ApplicationRecord +end diff --git a/app/views/friends/_form.html.erb b/app/views/friends/_form.html.erb new file mode 100644 index 0000000..d7dd541 --- /dev/null +++ b/app/views/friends/_form.html.erb @@ -0,0 +1,42 @@ +<%= form_with(model: friend) do |form| %> + <% if friend.errors.any? %> +
+

<%= pluralize(friend.errors.count, "error") %> prohibited this friend from being saved:

+ + +
+ <% end %> + +
+ <%= form.label :first_name %> + <%= form.text_field :first_name %> +
+ +
+ <%= form.label :last_name %> + <%= form.text_field :last_name %> +
+ +
+ <%= form.label :email %> + <%= form.text_field :email %> +
+ +
+ <%= form.label :phone %> + <%= form.text_field :phone %> +
+ +
+ <%= form.label :twitter %> + <%= form.text_field :twitter %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/friends/_friend.json.jbuilder b/app/views/friends/_friend.json.jbuilder new file mode 100644 index 0000000..e7c78da --- /dev/null +++ b/app/views/friends/_friend.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! friend, :id, :first_name, :last_name, :email, :phone, :twitter, :created_at, :updated_at +json.url friend_url(friend, format: :json) diff --git a/app/views/friends/edit.html.erb b/app/views/friends/edit.html.erb new file mode 100644 index 0000000..aa0abe1 --- /dev/null +++ b/app/views/friends/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Friend

+ +<%= render 'form', friend: @friend %> + +<%= link_to 'Show', @friend %> | +<%= link_to 'Back', friends_path %> diff --git a/app/views/friends/index.html.erb b/app/views/friends/index.html.erb new file mode 100644 index 0000000..ba1020f --- /dev/null +++ b/app/views/friends/index.html.erb @@ -0,0 +1,35 @@ +

<%= notice %>

+ +

Friend List

+ + + + + + + + + + + + + + + <% @friends.each do |friend| %> + + + + + + + + + + + <% end %> + +
First nameLast nameEmailPhoneTwitter
<%= friend.first_name %><%= friend.last_name %><%= friend.email %><%= friend.phone %><%= friend.twitter %><%= link_to 'Show', friend %><%= link_to 'Edit', edit_friend_path(friend) %><%= link_to 'Destroy', friend, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Friend', new_friend_path %> diff --git a/app/views/friends/index.json.jbuilder b/app/views/friends/index.json.jbuilder new file mode 100644 index 0000000..e5aa8a6 --- /dev/null +++ b/app/views/friends/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @friends, partial: "friends/friend", as: :friend diff --git a/app/views/friends/new.html.erb b/app/views/friends/new.html.erb new file mode 100644 index 0000000..4d83f8d --- /dev/null +++ b/app/views/friends/new.html.erb @@ -0,0 +1,5 @@ +

Add New Friend

+ +<%= render 'form', friend: @friend %> + +<%= link_to 'Back', friends_path %> diff --git a/app/views/friends/show.html.erb b/app/views/friends/show.html.erb new file mode 100644 index 0000000..1a31de4 --- /dev/null +++ b/app/views/friends/show.html.erb @@ -0,0 +1,29 @@ +

<%= notice %>

+ +

+ First name: + <%= @friend.first_name %> +

+ +

+ Last name: + <%= @friend.last_name %> +

+ +

+ Email: + <%= @friend.email %> +

+ +

+ Phone: + <%= @friend.phone %> +

+ +

+ Twitter: + <%= @friend.twitter %> +

+ +<%= link_to 'Edit', edit_friend_path(@friend) %> | +<%= link_to 'Back', friends_path %> diff --git a/app/views/friends/show.json.jbuilder b/app/views/friends/show.json.jbuilder new file mode 100644 index 0000000..48e293d --- /dev/null +++ b/app/views/friends/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "friends/friend", friend: @friend diff --git a/app/views/home/_header.html.erb b/app/views/home/_header.html.erb index 931489b..ccc4162 100644 --- a/app/views/home/_header.html.erb +++ b/app/views/home/_header.html.erb @@ -16,6 +16,18 @@ + + + +