-
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.
Turbo Frames for comments and answers (#19)
Answers and comments using turbo frames. Somewhat more complex use cases for this technology.
- Loading branch information
Showing
15 changed files
with
192 additions
and
136 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
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,34 +1,35 @@ | ||
<%= tag.article class: 'my-3 card border-0 border-top', id: dom_id(answer) do %> | ||
<div class="row g-0"> | ||
<div class="col-sm-auto text-sm-center align-self-center"> | ||
<%= answer.user.gravatar size: 50, css_class: 'd-block' %> | ||
<%= answer.user.name_or_email %> | ||
</div> | ||
<div class="col-sm"> | ||
<div class="card-body"> | ||
<section class="card-text mb-3"> | ||
<div class="col-sm-9"> | ||
<small><time datetime="<%= answer.formatted_created_at %>"> | ||
<%= answer.formatted_created_at %> | ||
</time></small> | ||
<%= turbo_frame_tag answer do %> | ||
<%= tag.article class: 'my-3 card border-0 border-top' do %> | ||
<div class="row g-0"> | ||
<div class="col-sm-auto text-sm-center align-self-center"> | ||
<%= answer.user.gravatar size: 50, css_class: 'd-block' %> | ||
<%= answer.user.name_or_email %> | ||
</div> | ||
<div class="col-sm"> | ||
<div class="card-body"> | ||
<section class="card-text mb-3"> | ||
<div class="col-sm-9"> | ||
<small><time datetime="<%= answer.formatted_created_at %>"> | ||
<%= answer.formatted_created_at %> | ||
</time></small> | ||
|
||
<div class="mt-2"> | ||
<%= sanitize answer.body %> | ||
<div class="mt-2"> | ||
<%= sanitize answer.body %> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
</section> | ||
|
||
<% if policy(answer).edit? %> | ||
<%= link_to t('global.button.edit'), edit_question_answer_path(question, answer), | ||
class: 'btn btn-info btn-sm' %> | ||
<% end %> | ||
<% if policy(answer).destroy? %> | ||
<%= link_to t('global.button.delete'), question_answer_path(question, answer), class: 'btn btn-danger btn-sm', | ||
data: {turbo_method: :delete, turbo_confirm: t('global.dialog.you_sure')} %> | ||
<% end %> | ||
<% if policy(answer).edit? %> | ||
<%= link_to t('global.button.edit'), edit_question_answer_path(question, answer), | ||
class: 'btn btn-info btn-sm' %> | ||
<% end %> | ||
<% if policy(answer).destroy? %> | ||
<%= link_to t('global.button.delete'), question_answer_path(question, answer), class: 'btn btn-danger btn-sm', | ||
data: {turbo_method: :delete, turbo_confirm: t('global.dialog.you_sure')} %> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<%= render 'comments/commentable', commentable: answer, comment: @comment %> | ||
<% end %> | ||
<%= render 'comments/commentable', commentable: answer, comment: @comment, | ||
html_id: dom_id(answer, 'comment_form') %> |
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,15 +1,16 @@ | ||
<%= render 'shared/errors', object: @answer %> | ||
<%= turbo_frame_tag @answer do %> | ||
<%= form_with model: [@question, @answer] do |f| %> | ||
<%= render 'shared/errors', object: @answer %> | ||
<div class="mb-3 row"> | ||
<div class="col-sm-2 col-form-label"> | ||
<%= f.label :body %> | ||
</div> | ||
|
||
<%= form_with model: [@question, @answer] do |f| %> | ||
<div class="mb-3 row"> | ||
<div class="col-sm-2 col-form-label"> | ||
<%= f.label :body %> | ||
<div class="col-sm-10"> | ||
<%= f.text_area :body, class: 'form-control', required: true %> | ||
</div> | ||
</div> | ||
|
||
<div class="col-sm-10"> | ||
<%= f.text_area :body, class: 'form-control', required: true %> | ||
</div> | ||
</div> | ||
|
||
<%= f.submit t('global.button.submit'), class: 'btn btn-primary' %> | ||
<%= f.submit t('global.button.submit'), class: 'btn btn-primary' %> | ||
<% 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 @@ | ||
<%= turbo_stream.prepend "answers", render(@answer, question: @answer.question) %> | ||
<%= prepend_flash %> |
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 @@ | ||
<%= turbo_stream.remove @answer %> | ||
<%= prepend_flash %> |
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 @@ | ||
<%= turbo_stream.replace @answer, render(@answer, question: @answer.question) %> | ||
<%= prepend_flash %> |
Oops, something went wrong.