generated from happiness-chain/rails_template
-
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.
Merge pull request #14 from KOH6/tweet_detail
ツイート詳細ページ作成
- Loading branch information
Showing
12 changed files
with
160 additions
and
28 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
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 @@ | ||
# frozen_string_literal: true | ||
|
||
class CommentsController < ApplicationController | ||
def create | ||
@comment = current_user.comments.build(comment_params) | ||
if @comment.save | ||
redirect_to request.referer | ||
else | ||
redirect_to request.referer, flash: { danger: 'コメント投稿に失敗しました。' } | ||
end | ||
end | ||
|
||
private | ||
|
||
def comment_params | ||
permit_params = params.require(:comment).permit(:content, images: []) | ||
permit_params.merge(post_id: params[:post_id].to_i) | ||
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
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,22 @@ | ||
.card | ||
.card-body.container-grid.text-dark | ||
.row | ||
.col-1 | ||
- if comment.user.photo.attached? | ||
= image_tag comment.user.photo, class: "rounded-circle img-fluid", style: " max-width: 100%; height: auto;" | ||
.col | ||
.d-flex.flex-row | ||
p.card-title.fw-bold | ||
= comment.user_name | ||
p.card-subtitle.text-muted.d-flex.align-items-center.mx-2 | ||
| @ | ||
= comment.user_user_name | ||
| ・ | ||
= l comment.created_at | ||
- if comment.content? | ||
span.card-text | ||
= safe_join(comment.content.split("\n"),tag(:br)) | ||
- if comment.images.attached? | ||
.d-flex.flex-row | ||
- comment.images.each do |image| | ||
= image_tag image, class: "img-fluid", style: " max-width: 50%; height: auto;" |
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,17 @@ | ||
- if user_signed_in? | ||
= form_with url: comments_path(post_id: post.id), model: comment, data: { turbo: false }, locale: true do |f| | ||
.card.my-3 | ||
.card-body.container-grid | ||
.row | ||
.col-1 | ||
- if user.photo.attached? | ||
= link_to user_path(current_user), data: { turbo: false } | ||
= image_tag user.photo, class: "rounded-circle img-fluid", style: " max-width: 100%; height: auto;" | ||
.col | ||
= f.text_area :content, class: 'form-control', placeholder: '返信をツイート', rows: 3 | ||
.d-flex.justify-content-between.mt-4 | ||
= f.label :images | ||
i.fs-3.bi-image.text-primary[style="cursor: pointer"] | ||
= f.file_field :images, multiple: true, style: "display: none" | ||
button.btn.btn-primary.px-4.text-white.fw-bold[type="submit"] | ||
| 返信 |
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,22 +1,23 @@ | ||
.card | ||
.card-body.container-grid | ||
.row | ||
.col-1 | ||
- if post.user.photo.attached? | ||
= image_tag post.user.photo, class: "rounded-circle img-fluid", style: " max-width: 100%; height: auto;" | ||
.col | ||
.d-flex.flex-row | ||
p.card-title.fw-bold | ||
= post.user_name | ||
p.card-subtitle.text-muted.d-flex.align-items-center.mx-2 | ||
| @ | ||
= post.user_user_name | ||
| ・ | ||
= l post.created_at | ||
- if post.content? | ||
span.card-text | ||
= safe_join(post.content.split("\n"),tag(:br)) | ||
- if post.images.attached? | ||
= link_to post_path(post), data: { turbo: false}, class: "post" | ||
.card-body.container-grid.text-dark | ||
.row | ||
.col-1 | ||
- if post.user.photo.attached? | ||
= image_tag post.user.photo, class: "rounded-circle img-fluid", style: " max-width: 100%; height: auto;" | ||
.col | ||
.d-flex.flex-row | ||
- post.images.each do |image| | ||
= image_tag image, class: "img-fluid", style: " max-width: 50%; height: auto;" | ||
p.card-title.fw-bold | ||
= post.user_name | ||
p.card-subtitle.text-muted.d-flex.align-items-center.mx-2 | ||
| @ | ||
= post.user_user_name | ||
| ・ | ||
= l post.created_at | ||
- if post.content? | ||
span.card-text | ||
= safe_join(post.content.split("\n"),tag(:br)) | ||
- if post.images.attached? | ||
.d-flex.flex-row | ||
- post.images.each do |image| | ||
= image_tag image, class: "img-fluid", style: " max-width: 50%; height: auto;" |
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,22 @@ | ||
.card | ||
.card-body.container-grid.text-dark | ||
.row.my-2 | ||
.col-1 | ||
- if post.user.photo.attached? | ||
= image_tag post.user.photo, class: "rounded-circle img-fluid", style: " max-width: 100%; height: auto;" | ||
.col | ||
p.card-title.fw-bold | ||
= post.user_name | ||
p.card-subtitle.text-muted.d-flex.align-items-center | ||
| @ | ||
= post.user_user_name | ||
.d-flex.flex-row | ||
- if post.content? | ||
span.card-text.my-2 | ||
= safe_join(post.content.split("\n"),tag(:br)) | ||
- if post.images.attached? | ||
.d-flex.flex-row.my-2 | ||
- post.images.each do |image| | ||
= image_tag image, class: "img-fluid", style: " max-width: 50%; height: auto;" | ||
p.card-subtitle.text-muted.d-flex.align-items-center | ||
= l post.created_at |
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 @@ | ||
.container-fluid | ||
= render 'shared/navigation' | ||
.row.flex-nowrap | ||
= render 'shared/sidebar', :user => @user | ||
.col | ||
= render "users/shared/error_messages", resource: @comment | ||
= render 'shared/flash' | ||
h3.fw-bold.my-3 | ||
| ツイート | ||
= render "post_detail", post: @post | ||
= render 'comments/form', :user => @user, :comment => @comment, :post => @post | ||
- @comments.each do |comment| | ||
= render comment | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Comments', type: :request do | ||
describe 'GET /index' do | ||
pending "add some examples (or delete) #{__FILE__}" | ||
end | ||
end |