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
4 changes: 4 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
quit
page.html
page.body
page.html
continue
page.html
quit
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
/*.swo
*.swo
.env
/coverage/*
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ group :test do
gem 'rspec-collection_matchers'
gem 'rspec-rails'
gem 'capybara'
gem 'poltergeist'
end
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ GEM
xpath (~> 2.0)
climate_control (0.0.3)
activesupport (>= 3.0)
cliver (0.3.2)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coderay (1.1.1)
Expand Down Expand Up @@ -136,6 +137,10 @@ GEM
activesupport (>= 3.1)
arel
pkg-config (1.1.7)
poltergeist (1.10.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -232,6 +237,9 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
will_paginate (3.1.0)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand All @@ -255,6 +263,7 @@ DEPENDENCIES
paperclip
pg (~> 0.15)
pg_search
poltergeist
rails (= 4.2.7.1)
rake
rspec-collection_matchers
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/likes.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/likes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the likes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
8 changes: 8 additions & 0 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class LikesController < ApplicationController

def create
@instruction = Instruction.find_by(title: params[:format].gsub('-', ' '))
@instruction.likes.create_with_user({}, current_user)
redirect_to(:back)
end
end
2 changes: 2 additions & 0 deletions app/helpers/likes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module LikesHelper
end
3 changes: 3 additions & 0 deletions app/models/instruction.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Instruction < ActiveRecord::Base
include PgSearch
include WithUserAssociationExtension
extend FriendlyId

friendly_id :title, use: :slugged
Expand All @@ -12,6 +13,8 @@ class Instruction < ActiveRecord::Base

belongs_to :user
belongs_to :category
has_many :likes, -> { extending WithUserAssociationExtension },
dependent: :destroy

has_attached_file :image, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
Expand Down
4 changes: 4 additions & 0 deletions app/models/like.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Like < ActiveRecord::Base
belongs_to :user
belongs_to :instruction
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable

has_many :instructions
has_many :likes
end
18 changes: 18 additions & 0 deletions app/models/with_user_association_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module WithUserAssociationExtension

def create_with_user(attributes = {}, user)
attributes[:user] ||= user
create(attributes)
end

def create_with_user!(attributes = {}, user)
attributes[:user] ||= user
create!(attributes)
end

def build_with_user(attributes = {}, user)
attributes[:user] ||= user
build(attributes)
end

end
5 changes: 5 additions & 0 deletions app/views/instructions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<%= image_tag @instruction.image.url(:thumb) %>
Category: <%= @instruction.category.name %>
<br>
Total <%= @instruction.likes.count %> likes
<br />
<%= form_tag likes_path(@instruction), :method => :post %>
<%= submit_tag 'Like' %>


<div id="disqus_thread"></div>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

devise_for :users

resources :likes
resources :instructions
resources :searches, :path => '/search'
resources :categories, :path => '/category'
Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 99.57
"covered_percent": 95.9
}
}
Loading