-
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.
Trying to add a comment form to wall index page
- Loading branch information
Showing
37 changed files
with
454 additions
and
53 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,55 @@ | ||
/*! | ||
* jQuery Textarea AutoSize plugin | ||
* Author: Javier Julio | ||
* Licensed under the MIT license | ||
*/ | ||
;(function ($, window, document, undefined) { | ||
|
||
var pluginName = "textareaAutoSize"; | ||
var pluginDataName = "plugin_" + pluginName; | ||
|
||
var containsText = function (value) { | ||
return (value.replace(/\s/g, '').length > 0); | ||
}; | ||
|
||
function Plugin(element, options) { | ||
this.element = element; | ||
this.$element = $(element); | ||
this.init(); | ||
} | ||
|
||
Plugin.prototype = { | ||
init: function() { | ||
var diff = parseInt(this.$element.css('paddingBottom')) + | ||
parseInt(this.$element.css('paddingTop')) + | ||
parseInt(this.$element.css('borderTopWidth')) + | ||
parseInt(this.$element.css('borderBottomWidth')) || 0; | ||
|
||
if (containsText(this.element.value)) { | ||
this.$element.height(this.element.scrollHeight - diff); | ||
} | ||
|
||
// keyup is required for IE to properly reset height when deleting text | ||
this.$element.on('input keyup', function(event) { | ||
var $window = $(window); | ||
var currentScrollPosition = $window.scrollTop(); | ||
|
||
$(this) | ||
.height(0) | ||
.height(this.scrollHeight - diff); | ||
|
||
$window.scrollTop(currentScrollPosition); | ||
}); | ||
} | ||
}; | ||
|
||
$.fn[pluginName] = function (options) { | ||
this.each(function() { | ||
if (!$.data(this, pluginDataName)) { | ||
$.data(this, pluginDataName, new Plugin(this, options)); | ||
} | ||
}); | ||
return this; | ||
}; | ||
|
||
})(jQuery, window, document); |
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 |
---|---|---|
|
@@ -2,5 +2,4 @@ | |
height: 24px | ||
width: 24px | ||
background-repeat: no-repeat | ||
background-size: auto | ||
content: '' |
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,2 +1,41 @@ | ||
class CommentsController < ApplicationController | ||
before_action :find_post | ||
This comment has been minimized.
Sorry, something went wrong. |
||
before_action :find_post, only: [:show, :edit, :update, :destroy] | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
def index | ||
@comments = @post.comment | ||
end | ||
|
||
def new | ||
@comment = Comment.new | ||
@comment = @post.comment.build | ||
end | ||
|
||
def create | ||
@comment = @post.comments.create(params[:comment].permit(:content)) | ||
This comment has been minimized.
Sorry, something went wrong.
GomaaK
Collaborator
|
||
@comment.post_id = @post.id | ||
This comment has been minimized.
Sorry, something went wrong.
GomaaK
Collaborator
|
||
@comment.user_id = current_user.id | ||
# @comment = @post.comments.create(params[:comment].permit[:content]) | ||
# @comment.post_id = @post.id | ||
if @comment.save | ||
redirect_to root_path | ||
# format.json { render :show, status: :created, location: @post } | ||
else | ||
render 'new' | ||
end | ||
|
||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
# def comment_params | ||
# params.require(:comment).permit(:content) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
# end | ||
|
||
def find_post | ||
@post = Post.find(params[:post_id]) | ||
end | ||
|
||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
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,12 +1,14 @@ | ||
class WallsController < ApplicationController | ||
respond_to :json, :html | ||
|
||
|
||
def index | ||
@posts = Post.order("created_at DESC") | ||
@post = Post.new | ||
@walls = Wall.all.includes(:user, :post).to_json(:include => [{post: {only: %i(username image content youtube_url)}},{:user => {only: %i(id)}}]) | ||
@walls = Wall.all.includes(:user, :post, :comment).to_json(:include => [{post: {only: %i(username image content youtube_url)}},{:user => {only: %i(id)}},{:comment => {only: %i(content)}}]) | ||
respond_with @wall | ||
@user = User.all | ||
@comment = Comment.new | ||
@comments = Comment.order("created_at DESC") | ||
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,5 @@ | ||
$white: #fff | ||
$dark-blue: #101b25 | ||
$border-color: #ece8e8 | ||
$black: #000 | ||
$fb-blue: #1c4c77 |
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,25 @@ | ||
.m-top | ||
margin-top: 3em | ||
|
||
.n-m | ||
margin: 0 | ||
|
||
.card | ||
background-color: #fff | ||
padding: 0.75em | ||
border: 1px solid #ece8e8 | ||
border-radius: 4px | ||
width: 100% | ||
max-width: 100% | ||
margin-bottom: 1em | ||
position: relative | ||
|
||
.bold | ||
font-weight: bold | ||
|
||
img | ||
height: auto | ||
max-width: 100% | ||
|
||
.table | ||
display: table |
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,2 +1,4 @@ | ||
class Comment < ApplicationRecord | ||
belongs_to :post | ||
belongs_to :user | ||
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
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 @@ | ||
|
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,6 @@ | ||
<div class="comments"> | ||
<%= form_for([@post, @post.comments.build]) do |f| %> | ||
<%= f.text_area :content, class: 'comments js-auto-size', id: 'alex2' ,:rows => 1 %> | ||
<%= f.submit "Submit", class: "btn btn-default" %> | ||
<% end %> | ||
</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,3 @@ | ||
<%= @comments.each do |comment| %> | ||
<h2><%= comment.content %></h2> | ||
<% 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 @@ | ||
<h2> New Comment </h2> | ||
<%= 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h2> <%= @comment.content %></h2> |
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 |
---|---|---|
|
@@ -25,5 +25,5 @@ | |
</table> | ||
|
||
<br> | ||
|
||
<%= link_to "Comments", new_post_comment_path(@post) %> | ||
<%= link_to 'New Post', new_post_path %> |
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
<%= @post.image %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_post_path(@post) %> | | ||
<%= link_to 'Back', posts_path %> |
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,5 @@ | ||
<div class="product-reviews"> | ||
<% @comments.each do |comment| %> | ||
<p><%= comment.content %></p> | ||
<% end %> | ||
</div> |
Oops, something went wrong.
this is override by the next line