Skip to content
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
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gem 'sass-rails', '~> 4.0.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'turbolinks'
gem 'bootstrap-sass', '~> 3.3'

Expand Down Expand Up @@ -52,7 +53,7 @@ gem 'bugsnag'
gem 'redcarpet'

# API stackoverflow
gem 'ruby-stackoverflow', git: 'https://github.com/PowerCodeGirls/ruby-stackoverflow.git'
gem 'ruby-stackoverflow', git: 'https://github.com/PowerCodeGirls/ruby-stackoverflow.git'

gem 'sidekiq'
gem "sidekiq-cron", "~> 0.3.0"
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ GEM
jquery-rails (3.1.3)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
json (1.8.3)
jwt (1.5.1)
launchy (2.4.3)
Expand Down Expand Up @@ -327,6 +329,7 @@ DEPENDENCIES
guard-rspec
jbuilder (~> 1.2)
jquery-rails
jquery-ui-rails
launchy
newrelic_rpm
omniauth
Expand Down
83 changes: 81 additions & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .
Expand All @@ -20,7 +21,7 @@ $(function(){
$('#welcome_message').bind('closed.bs.alert', function() {
var form = $('#welcome_message').next('form');
$.post(form.attr('action'), form.serialize());
})
});

$('#digest_signup_form')
.bind("ajax:success", function(data, status, xhr) {
Expand All @@ -29,4 +30,82 @@ $(function(){
.bind("ajax:error", function(xhr, status, error) {
alert('Failed.');
});
})
});

$(function() {
$('.tags-input').autocomplete({
minLength: 1,
source: "/tags.json",
autoFocus: true,

focus: function() {
// prevent value inserted on focus
return false;
},

select: function(event, ui) {
var terms = this.value.split(/,\s*/);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add an empty item for a trailing comma
terms.push("");

this.value = terms.join(", ");
$(this).autocomplete('close');
return false;
}
});

$('.tags-input').on('blur', function() {
// remove any trailing commas
this.value = this.value.replace(/,\s*$/, '');
});
});

$(function() {
$(".vote-count a").on('click', function() {
var link = $(this);
var url = $(this).attr('href');

$.ajax({
url: url,
type: "PUT",

success: function(response) {
link.replaceWith(response);
}
});

return false;
});
});

$(function() {
$(".post-link").on('click', function() {
var link = $(this);
var url = link.attr('href');
var container = link.parent('td');

if (container.find('.post-summary:visible').length > 0) {
$('.post-summary').slideUp();
} else if (container.find('.post-summary:hidden').length > 0) {
container.find('.post-summary:hidden').slideDown();
} else {
$('.post-summary').slideUp();

$.ajax({
url: url,
success: function(response) {
var postSummary = $(response);
postSummary.hide();
container.append(postSummary);
postSummary.slideDown();
}
})
}

return false;
});
});
17 changes: 13 additions & 4 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def index
def show
@comment = Comment.new
@comment.parent = @post

if request.xhr?
render partial: 'posts/post_summary'
end
end

# GET /posts/new
Expand Down Expand Up @@ -72,11 +76,16 @@ def destroy
end
end

def vote
def vote
@post = Post.find(params[:id])
@post.add_vote(current_user)
flash[:notice] = "You have successfully voted"
redirect_to(:back)

if request.xhr?
render partial: 'votes/vote', locals: {post: @post}
else
flash[:notice] = "You have successfully voted"
redirect_to(:back)
end
end

private
Expand All @@ -97,4 +106,4 @@ def post_params
params.require(post_type.underscore.to_sym).
permit(:title, :body_markdown, :user_id, :tags_string)
end
end
end
8 changes: 5 additions & 3 deletions app/views/posts/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
<td>
<% if post.instance_of? Guide %>
<%= image_tag 'Guide.png', alt: 'Guides', class: 'guide-xs pull-left show', width: 25 %>
<% end %>
<%= link_to post.title, post_path(post) %>
<% end %>

<%= link_to post.title, post_path(post), class: 'post-link' %>

<br><span class="text-muted">Submitted by <%= post.username %> on <%= post.created_at.strftime("%m/%d/%Y") %></span>
<br><%= render 'posts/tags', post: post %>
</td>
Expand All @@ -17,4 +19,4 @@
</tr>
<% end %>
</tbody>
</table>
</table>
15 changes: 15 additions & 0 deletions app/views/posts/_post_summary.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="post-summary">
<% if @post.type == "Guide" %>
<p>
<h4>Category: <%= @post.category.name %></h4>
</p>
<% end %>

<div class="body">
<%= raw @post.body_html %>
<% if @post.external_post? %>
<p><%= link_to 'Visit Website', @post.source_url %></p>
<% end %>
<%= link_to "View post details", post_path(@post) %>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<div class="post">
<h1>
<%= @post.title %>
<%= render 'votes/vote', post: @post %>
<%= render 'posts/post_summary', post: @post %>
<% if @post.instance_of? Guide %>
<%= image_tag 'Guide.png', alt: 'Guides', class: 'guide-xs pull-left show', width: 25 %>
<% end %>
<% end %>
</h1>

<% if @post.type == "Guide" %>
Expand Down