-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix #384: allow commenting on a point * clean up comments adding
- Loading branch information
1 parent
0718638
commit e8b2232
Showing
6 changed files
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class CommentsController < ApplicationController | ||
before_action :authenticate_user!, except: [:index, :show] | ||
before_action :set_point, only: [:new, :create] | ||
def new | ||
@comment = Comment.new | ||
end | ||
|
||
def create | ||
@comment = Comment.new(comment_params) | ||
@comment.point = @point | ||
|
||
if @comment.save | ||
flash[:notice] = "Comment added!" | ||
else | ||
flash[:notice] = "Error adding comment!" | ||
puts @comment.errors.full_messages | ||
end | ||
redirect_to point_path(@point) | ||
end | ||
|
||
private | ||
|
||
def set_point | ||
@point = Point.find(params[:point_id]) | ||
end | ||
|
||
def comment_params | ||
params.require(:comment).permit(:summary) | ||
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Comment < ApplicationRecord | ||
belongs_to :point | ||
|
||
validates :summary, presence: true | ||
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,16 @@ | ||
<div class="form-login"> | ||
<div class="row row-form"> | ||
<%= simple_form_for([@point, @comment]) do |f| %> | ||
<div class="form-inputs col-xs-12"> | ||
<%= f.input :summary %> | ||
</div> | ||
<div class="form-actions col-xs-4 col-sm-2 col-md-2"> | ||
<%= link_to "Back", :back, class: "btn btn-default" %> | ||
</div> | ||
<div class="form-actions col-xs-8 col-sm-4 col-sm-offset-6 col-md-3 col-md-offset-7"> | ||
<%= f.submit class: 'btn btn-primary' %> | ||
</div> | ||
<% end %> | ||
</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,2 @@ | ||
<%= render '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
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