Skip to content

Commit

Permalink
added views
Browse files Browse the repository at this point in the history
  • Loading branch information
prithvi16 committed Sep 11, 2017
1 parent 9a766d9 commit 2cee60a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
10 changes: 9 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@

.new-paste {
font-size: 30px;
font-weight: bold;
font-weight: 500;
margin-top: 20px;
a{
color: #222;

}

a :hover {
color: #222;
}
}

.btn-primary {
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/index_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ def new
def show

@paste = Paste.find_by hash_number: params[:id]

recently_viewed = cookies[:viewd_posts].to_s.split(':')
if not recently_viewed.include?(@paste.hash_number.to_s)
@paste.update_column(:views, @paste.views+1 )
recently_viewed << @paste.hash_number.to_s
end
cookies[:viewd_posts] = {
value: recently_viewed.join(':'),
expires: 10.minutes.from_now
}
end


Expand Down
3 changes: 2 additions & 1 deletion app/views/index/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

<span>
<h1 class="paste-title"> <%= @paste.title %></h1><input id="address" value="<%= request.original_url %>" > <button class="clipboard-btn" data-clipboard-action="copy" data-clipboard-target="#address">
Copy to clipboard
Copy to clipboard
</button> </span>
<hr>
<p><%= @paste.views %> Views</p>
<p id="paste-body" > <%= markdown2 (@paste.content) %> </p>


Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170911095041_remove_pass_key_from_pastes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemovePassKeyFromPastes < ActiveRecord::Migration[5.1]
def change
remove_column :pastes, :pass_key, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170911095201_remove_pass_checker_from_pastes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemovePassCheckerFromPastes < ActiveRecord::Migration[5.1]
def change
remove_column :pastes, :pass_checker, :boolean
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170911095322_add_views_to_pastes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddViewsToPastes < ActiveRecord::Migration[5.1]
def change
add_column :pastes, :views, :integer , default: 0
end
end
5 changes: 2 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170909114507) do
ActiveRecord::Schema.define(version: 20170911095322) do

create_table "pastes", force: :cascade do |t|
t.string "title"
t.text "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "hash_number"
t.string "pass_key"
t.boolean "pass_checker", default: false
t.integer "views", default: 0
t.index ["hash_number"], name: "index_pastes_on_hash_number"
end

Expand Down

0 comments on commit 2cee60a

Please sign in to comment.