Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[F] POST/COMMENT when Enter hit dubla 2 ;) #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/assets/javascripts/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function submit_comment(event, post) {
if (event.keyCode == 13) {
jQuery('#new-c' + post + ' > form').submit();
return false;
}
}
3 changes: 0 additions & 3 deletions app/assets/javascripts/comment.js.coffee

This file was deleted.

10 changes: 9 additions & 1 deletion app/assets/javascripts/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ function showPosition(position)
jQuery('#feed_latitude').val(position.coords.latitude);
jQuery('#feed_longitude').val(position.coords.longitude);
}


jQuery(document).ready(function() {
jQuery('#feed_post').keydown(function(event) {
if (event.keyCode == 13) {
this.form.submit();
return false;
}
});
});
9 changes: 7 additions & 2 deletions app/controllers/comment_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ def new
end

def create
comment = params.require(:feed).require :comment
post = params.permit([:post])[:post]
begin
comment = params.require(:feed).require :comment
post = params.permit([:post])[:post]
rescue ActionController::ParameterMissing
redirect_to :feed_index, :alert => 'The comment should contain a message'
return
end

if post
current_user.family.posts.find_by_id(post).comments.create :text => comment, :user => current_user
Expand Down
2 changes: 1 addition & 1 deletion app/views/comment/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_tag({:action => 'create', :controller => 'comment'}, :method => :comment) %>
<%= text_area :feed, 'comment', :rows => 2, :cols => 240, :style=> 'width:420px' %>
<%= text_area :feed, "comment", :rows => 2, :cols => 240, :style=> 'width:420px', :onkeydown => "submit_comment(event, #{@post});" %>
<% if @post %>
<%= hidden_field_tag :post, @post %>
<% elsif @event %>
Expand Down