-
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
814bb21
commit 0f8d7fd
Showing
22 changed files
with
583 additions
and
7 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
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,59 @@ | ||
# frozen_string_literal: true | ||
|
||
class CommentsController < ApplicationController | ||
def index | ||
@comments = Comment.order("created_at DESC") | ||
end | ||
|
||
def new | ||
@comment = Comment.new | ||
end | ||
|
||
def edit | ||
find_comment | ||
end | ||
|
||
def show | ||
find_comment | ||
@attachments = Uploadcare::GroupApi.get_group(@comment.attachments.load.id)["files"] if @comment.attachments | ||
end | ||
|
||
def create | ||
@comment = Comment.new(comment_params) | ||
if @comment.save | ||
flash[:success] = "Comment has been successfully created!" | ||
redirect_to comment_path(@comment) | ||
else | ||
flash.now[:alert] = @comment.errors.full_messages.join("; ") | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
find_comment | ||
if @comment.update(comment_params) | ||
flash[:success] = "Comment has been successfully updated!" | ||
redirect_to comment_path(@comment) | ||
else | ||
flash.now[:alert] = @comment.errors.full_messages.join("; ") | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
find_comment | ||
@comment.destroy | ||
flash[:success] = "Comment has been successfully deleted!" | ||
redirect_to comments_path | ||
end | ||
|
||
private | ||
|
||
def comment_params | ||
params.require(:comment).permit(:content, :image, :attachments) | ||
end | ||
|
||
def find_comment | ||
@comment = Comment.find(params[:id]) | ||
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Comment | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
field :content, type: String | ||
field :image, type: String | ||
field :attachments, type: String | ||
|
||
mount_uploadcare_file :image | ||
mount_uploadcare_file_group :attachments | ||
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,21 @@ | ||
<%= form_tag(path, method: method) do %> | ||
|
||
<div class="mb-3"> | ||
<label class="mb-0">Content</label> | ||
<%= text_field_tag :content, local_assigns[:comment_content], name: 'comment[content]', class: 'form-control' %> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label class="mb-0">File image</label><br> | ||
<%= uploadcare_uploader_field :comment, :image, class: 'mb-3' %> | ||
</div> | ||
|
||
<div class="mb-4"> | ||
<label class="mb-0">File attachments</label><br> | ||
<%= uploadcare_uploader_field :comment, :attachments %> | ||
</div> | ||
|
||
<div> | ||
<%= submit_tag 'Save', class: 'btn btn-primary' %> | ||
</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,7 @@ | ||
<h1>Edit comment</h1> | ||
|
||
<div class="card"> | ||
<div class="card-body border"> | ||
<%= render 'comments/form', path: comment_path(@comment), method: :patch, comment_content: @comment.content %> | ||
</div> | ||
</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,17 @@ | ||
<h1>Comments</h1> | ||
|
||
<% if @comments.present? %> | ||
<% @comments.each do |comment| %> | ||
<li class="list-group-item d-flex justify-content-between align-items-center"> | ||
<div class="text-place flex-grow-1 text-truncate"> | ||
<%= link_to comment.content, comment_path(comment) %> | ||
</div> | ||
<div class="btn-group" role="group" aria-label="Actions"> | ||
<%= link_to 'Edit', edit_comment_path(comment), class: "btn btn-secondary btn-sm" %> | ||
<%= link_to 'Delete', comment_path(comment), method: :delete, class: "btn btn-danger btn-sm" %> | ||
</div> | ||
</li> | ||
<% end %> | ||
<% else %> | ||
<span>No comments found. Please, create a one <%= link_to 'here', new_comment_path, class: 'd-inline' %>!</span> | ||
<% 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,7 @@ | ||
<h1>Create a new comment</h1> | ||
|
||
<div class="card"> | ||
<div class="card-body border"> | ||
<%= render 'comments/form', path: comments_path, method: :post %> | ||
</div> | ||
</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,51 @@ | ||
<h1> | ||
Comment "<%= @comment.content %>" | ||
<div class="d-inline mr-0"> | ||
<%= link_to 'Edit', edit_comment_path(@comment), class: "btn btn-secondary" %> | ||
<%= link_to 'Delete', comment_path(@comment), method: :delete, class: "btn btn-danger" %> | ||
</div> | ||
</h1> | ||
|
||
<h4 class="d-flex justify-content-between align-items-center mt-5"> | ||
Image | ||
</h4> | ||
<% if @comment.image? %> | ||
<li class="list-group-item d-flex justify-content-between align-items-center"> | ||
<div class="text-place flex-grow-1 text-truncate"> | ||
<%= link_to @comment.image.load.original_filename, file_path(@comment.image.uuid) %> | ||
<br> | ||
<div class="badge badge-secondary"><%= @comment.image.uuid %></div> | ||
<div class="badge badge-secondary"><%= @comment.image.mime_type %></div> | ||
</div> | ||
<div class="btn-group" role="group" aria-label="Actions"> | ||
<%= link_to 'Copy', copy_file_path(@comment.image.uuid), method: :post, class: "btn btn-secondary btn-sm" %> | ||
<%= link_to 'Store', store_file_path(@comment.image.uuid), method: :post, class: "btn btn-secondary btn-sm" %> | ||
<%= link_to 'Delete', file_path(@comment.image.uuid), method: :delete, class: "btn btn-danger btn-sm" %> | ||
</div> | ||
</li> | ||
<% else %> | ||
-- | ||
<% end %> | ||
|
||
<h4 class="d-flex justify-content-between align-items-center mt-4"> | ||
Attachments | ||
</h4> | ||
<% if @attachments.present? %> | ||
<% @attachments.each do |file| %> | ||
<li class="list-group-item d-flex justify-content-between align-items-center"> | ||
<div class="text-place flex-grow-1 text-truncate"> | ||
<%= link_to file.original_filename, file_path(file.uuid) %> | ||
<br> | ||
<div class="badge badge-secondary"><%= file.uuid %></div> | ||
<div class="badge badge-secondary"><%= file.mime_type %></div> | ||
</div> | ||
<div class="btn-group" role="group" aria-label="Actions"> | ||
<%= link_to 'Copy', copy_file_path(file.uuid), method: :post, class: "btn btn-secondary btn-sm" %> | ||
<%= link_to 'Store', store_file_path(file.uuid), method: :post, class: "btn btn-secondary btn-sm" %> | ||
<%= link_to 'Delete', file_path(file.uuid), method: :delete, class: "btn btn-danger btn-sm" %> | ||
</div> | ||
</li> | ||
<% end %> | ||
<% else %> | ||
-- | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
APP_PATH = File.expand_path("../config/application", __dir__) | ||
require_relative "../config/boot" | ||
require "rails/commands" | ||
require "railsmdb/commands" |
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,4 @@ | ||
#!/usr/bin/env ruby | ||
APP_PATH = File.expand_path("../config/application", __dir__) | ||
require_relative "../config/boot" | ||
require "railsmdb/commands" |
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,26 @@ | ||
require "mongoid" | ||
|
||
Mongoid.configure do | ||
target_version = "9.0" | ||
|
||
# Load Mongoid behavior defaults. This automatically sets | ||
# feature flags (refer to documentation) | ||
config.load_defaults target_version | ||
|
||
# It is recommended to use config/mongoid.yml for most Mongoid-related | ||
# configuration, whenever possible, but if you prefer, you can set | ||
# configuration values here, instead: | ||
# | ||
# config.log_level = :debug | ||
# | ||
# Note that the settings in config/mongoid.yml always take precedence, | ||
# whatever else is set here. | ||
end | ||
|
||
# Enable Mongo driver query cache for Rack | ||
# Rails.application.config.middleware.use(Mongo::QueryCache::Middleware) | ||
|
||
# Enable Mongo driver query cache for ActiveJob | ||
# ActiveSupport.on_load(:active_job) do | ||
# include Mongo::QueryCache::Middleware::ActiveJob | ||
# end |
Oops, something went wrong.