Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ss add devise #59

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-3.2.1
ruby-3.1.2
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.2.1"

gem "simple_form"

ruby "3.1.2"
gem "devise"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.4", ">= 7.0.4.3"

Expand Down
17 changes: 16 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ GEM
tabulo
awesome_print (1.9.2)
base64 (0.1.1)
bcrypt (3.1.20)
better_errors (2.9.1)
coderay (>= 1.0.0)
erubi (>= 1.0.0)
Expand Down Expand Up @@ -109,6 +110,12 @@ GEM
irb (>= 1.5.0)
reline (>= 0.3.1)
debug_inspector (1.1.0)
devise (4.9.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.5.0)
diffy (3.4.2)
domain_name (0.5.20190701)
Expand Down Expand Up @@ -215,6 +222,7 @@ GEM
faraday (>= 1, < 3)
sawyer (~> 0.9)
oj (3.13.23)
orm_adapter (0.5.0)
pg (1.4.6)
pry (0.14.2)
coderay (~> 1.1)
Expand Down Expand Up @@ -278,6 +286,9 @@ GEM
regexp_parser (2.8.2)
reline (0.3.9)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
Expand Down Expand Up @@ -357,6 +368,8 @@ GEM
unf_ext
unf_ext (0.0.9.1)
unicode-display_width (2.4.2)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -386,6 +399,7 @@ GEM
zeitwerk (2.6.12)

PLATFORMS
x86_64-darwin-19
x86_64-darwin-22
x86_64-linux

Expand All @@ -398,6 +412,7 @@ DEPENDENCIES
bootsnap
capybara
debug
devise
dotenv-rails
draft_matchers
faker
Expand Down Expand Up @@ -431,7 +446,7 @@ DEPENDENCIES
webmock

RUBY VERSION
ruby 3.2.1p31
ruby 3.1.2p20

BUNDLED WITH
2.4.6
70 changes: 70 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class CommentsController < ApplicationController
before_action :set_comment, only: %i[ show edit update destroy ]

# GET /comments or /comments.json
def index
@comments = Comment.all
end

# GET /comments/1 or /comments/1.json
def show
end

# GET /comments/new
def new
@comment = Comment.new
end

# GET /comments/1/edit
def edit
end

# POST /comments or /comments.json
def create
@comment = Comment.new(comment_params)

respond_to do |format|
if @comment.save
format.html { redirect_to comment_url(@comment), notice: "Comment was successfully created." }
format.json { render :show, status: :created, location: @comment }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /comments/1 or /comments/1.json
def update
respond_to do |format|
if @comment.update(comment_params)
format.html { redirect_to comment_url(@comment), notice: "Comment was successfully updated." }
format.json { render :show, status: :ok, location: @comment }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end

# DELETE /comments/1 or /comments/1.json
def destroy
@comment.destroy

respond_to do |format|
format.html { redirect_to comments_url, notice: "Comment was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_comment
@comment = Comment.find(params[:id])
end

# Only allow a list of trusted parameters through.
def comment_params
params.require(:comment).permit(:author_id, :photo_id, :body)
end
end
70 changes: 70 additions & 0 deletions app/controllers/follow_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class FollowRequestsController < ApplicationController
before_action :set_follow_request, only: %i[ show edit update destroy ]

# GET /follow_requests or /follow_requests.json
def index
@follow_requests = FollowRequest.all
end

# GET /follow_requests/1 or /follow_requests/1.json
def show
end

# GET /follow_requests/new
def new
@follow_request = FollowRequest.new
end

# GET /follow_requests/1/edit
def edit
end

# POST /follow_requests or /follow_requests.json
def create
@follow_request = FollowRequest.new(follow_request_params)

respond_to do |format|
if @follow_request.save
format.html { redirect_to follow_request_url(@follow_request), notice: "Follow request was successfully created." }
format.json { render :show, status: :created, location: @follow_request }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @follow_request.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /follow_requests/1 or /follow_requests/1.json
def update
respond_to do |format|
if @follow_request.update(follow_request_params)
format.html { redirect_to follow_request_url(@follow_request), notice: "Follow request was successfully updated." }
format.json { render :show, status: :ok, location: @follow_request }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @follow_request.errors, status: :unprocessable_entity }
end
end
end

# DELETE /follow_requests/1 or /follow_requests/1.json
def destroy
@follow_request.destroy

respond_to do |format|
format.html { redirect_to follow_requests_url, notice: "Follow request was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_follow_request
@follow_request = FollowRequest.find(params[:id])
end

# Only allow a list of trusted parameters through.
def follow_request_params
params.require(:follow_request).permit(:recipient_id, :sender_id, :status)
end
end
70 changes: 70 additions & 0 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class LikesController < ApplicationController
before_action :set_like, only: %i[ show edit update destroy ]

# GET /likes or /likes.json
def index
@likes = Like.all
end

# GET /likes/1 or /likes/1.json
def show
end

# GET /likes/new
def new
@like = Like.new
end

# GET /likes/1/edit
def edit
end

# POST /likes or /likes.json
def create
@like = Like.new(like_params)

respond_to do |format|
if @like.save
format.html { redirect_to like_url(@like), notice: "Like was successfully created." }
format.json { render :show, status: :created, location: @like }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /likes/1 or /likes/1.json
def update
respond_to do |format|
if @like.update(like_params)
format.html { redirect_to like_url(@like), notice: "Like was successfully updated." }
format.json { render :show, status: :ok, location: @like }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
end
end
end

# DELETE /likes/1 or /likes/1.json
def destroy
@like.destroy

respond_to do |format|
format.html { redirect_to likes_url, notice: "Like was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_like
@like = Like.find(params[:id])
end

# Only allow a list of trusted parameters through.
def like_params
params.require(:like).permit(:fan_id, :photo_id)
end
end
70 changes: 70 additions & 0 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class PhotosController < ApplicationController
before_action :set_photo, only: %i[ show edit update destroy ]

# GET /photos or /photos.json
def index
@photos = Photo.all
end

# GET /photos/1 or /photos/1.json
def show
end

# GET /photos/new
def new
@photo = Photo.new
end

# GET /photos/1/edit
def edit
end

# POST /photos or /photos.json
def create
@photo = Photo.new(photo_params)

respond_to do |format|
if @photo.save
format.html { redirect_to photo_url(@photo), notice: "Photo was successfully created." }
format.json { render :show, status: :created, location: @photo }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @photo.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /photos/1 or /photos/1.json
def update
respond_to do |format|
if @photo.update(photo_params)
format.html { redirect_to photo_url(@photo), notice: "Photo was successfully updated." }
format.json { render :show, status: :ok, location: @photo }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @photo.errors, status: :unprocessable_entity }
end
end
end

# DELETE /photos/1 or /photos/1.json
def destroy
@photo.destroy

respond_to do |format|
format.html { redirect_to photos_url, notice: "Photo was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_photo
@photo = Photo.find(params[:id])
end

# Only allow a list of trusted parameters through.
def photo_params
params.require(:photo).permit(:image, :comments_count, :likes_count, :caption, :owner_id)
end
end
25 changes: 25 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# == Schema Information
#
# Table name: comments
#
# id :bigint not null, primary key
# body :text not null
# created_at :datetime not null
# updated_at :datetime not null
# author_id :bigint not null
# photo_id :bigint not null
#
# Indexes
#
# index_comments_on_photo_id (photo_id)
#
# Foreign Keys
#
# fk_rails_... (author_id => users.id)
# fk_rails_... (photo_id => photos.id)
#
class Comment < ApplicationRecord
belongs_to :author, class_name: "User", counter_cache: true
belongs_to :photo
validates :body, presence: true
end
Loading