ajout fonction nombre de vues
This commit is contained in:
parent
4ada778208
commit
6febd47f2c
@ -28,6 +28,16 @@ class Forum::ForumTopicsController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
@topic = ForumTopic.find(params[:id])
|
@topic = ForumTopic.find(params[:id])
|
||||||
|
session[:topics] = session[:topics] || []
|
||||||
|
if session[:topics].include?(@topic.id)
|
||||||
|
topic_viewed = current_fuser.forum_user_topic_vieweds.where(:forum_topic_id => @topic.id).order("created_at DESC").first
|
||||||
|
topic_viewed.updated_at = Time.now
|
||||||
|
topic_viewed.save
|
||||||
|
else
|
||||||
|
current_fuser.topic_vieweds << @topic
|
||||||
|
session[:topics] << @topic.id
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
class ForumTopic < ActiveRecord::Base
|
class ForumTopic < ActiveRecord::Base
|
||||||
belongs_to :forum_user
|
belongs_to :forum_user
|
||||||
#attr_accessible :description, :title, :forum_messages_attributes, :category_id
|
#attr_accessible :description, :title, :forum_messages_attributes, :category_id
|
||||||
|
has_many :forum_user_topic_vieweds
|
||||||
|
|
||||||
has_many :followed_topics
|
has_many :followed_topics
|
||||||
has_many :forum_users, :through => :followed_topics do
|
has_many :forum_users, :through => :followed_topics do
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
class ForumUser < ActiveRecord::Base
|
class ForumUser < ActiveRecord::Base
|
||||||
#attr_accessible :bio, :email, :firstname, :name, :password, :password_confirmation, :avatar, :moderator
|
#attr_accessible :bio, :email, :firstname, :name, :password, :password_confirmation, :avatar, :moderator
|
||||||
|
|
||||||
|
has_many :topic_vieweds, :through => :forum_user_topic_vieweds, :source => :forum_topic
|
||||||
|
|
||||||
|
has_many :forum_user_topic_vieweds
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
has_many :followed_topics
|
has_many :followed_topics
|
||||||
has_many :forum_topics, :through => :followed_topics do
|
has_many :forum_topics, :through => :followed_topics do
|
||||||
|
4
app/models/forum_user_topic_viewed.rb
Normal file
4
app/models/forum_user_topic_viewed.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class ForumUserTopicViewed < ActiveRecord::Base
|
||||||
|
belongs_to :forum_topic
|
||||||
|
belongs_to :forum_user
|
||||||
|
end
|
@ -1,7 +1,14 @@
|
|||||||
%tr.topic#topic{:id => forum_topic.id}
|
%tr.topic#topic{:id => forum_topic.id}
|
||||||
%td=link_to forum_topic.title, [:forum, forum_topic]
|
%td=link_to forum_topic.title, [:forum, forum_topic]
|
||||||
%td{:style => "width:160px;"}=forum_topic.category.title if forum_topic.category
|
%td{:style => "width:160px;"}=forum_topic.category.title if forum_topic.category
|
||||||
%td{:style => "width:100px;"}=forum_topic.forum_messages.count - 1
|
%td{:style => "width:100px;"}
|
||||||
|
=forum_topic.forum_messages.count - 1
|
||||||
|
%br
|
||||||
|
vu
|
||||||
|
= forum_topic.forum_user_topic_vieweds.count
|
||||||
|
fois
|
||||||
|
-#views = forum_topic.forum_user_topic_vieweds.select("DISTINCT forum_user_id").count
|
||||||
|
|
||||||
%td{:style => "width:160px;"}
|
%td{:style => "width:160px;"}
|
||||||
= forum_topic.username
|
= forum_topic.username
|
||||||
%br
|
%br
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
=link_to "ajouter un message", new_forum_forum_message_path(:topic_id => @topic.id), :class => "btn btn-primary", :style => "margin:1em 0em;float:right"
|
=link_to "ajouter un message", new_forum_forum_message_path(:topic_id => @topic.id), :class => "btn btn-primary", :style => "margin:1em 0em;float:right"
|
||||||
|
|
||||||
%h1
|
%h1
|
||||||
|
10
db/migrate/20150121145821_create_forum_user_topic_vieweds.rb
Normal file
10
db/migrate/20150121145821_create_forum_user_topic_vieweds.rb
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class CreateForumUserTopicVieweds < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :forum_user_topic_vieweds do |t|
|
||||||
|
t.references :forum_topic, index: true
|
||||||
|
t.references :forum_user, index: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
22
db/schema.rb
22
db/schema.rb
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141209215455) do
|
ActiveRecord::Schema.define(version: 20150121145821) do
|
||||||
|
|
||||||
create_table "admins", force: true do |t|
|
create_table "admins", force: true do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
@ -24,14 +24,20 @@ ActiveRecord::Schema.define(version: 20141209215455) do
|
|||||||
t.datetime "last_sign_in_at"
|
t.datetime "last_sign_in_at"
|
||||||
t.string "current_sign_in_ip"
|
t.string "current_sign_in_ip"
|
||||||
t.string "last_sign_in_ip"
|
t.string "last_sign_in_ip"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at", null: false
|
||||||
t.string "username"
|
t.string "username"
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "firstname"
|
t.string "firstname"
|
||||||
t.string "file"
|
t.string "file"
|
||||||
|
t.string "avatar"
|
||||||
|
t.string "password_digest", default: "", null: false
|
||||||
|
t.string "remember_token"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "admins", ["email"], name: "index_admins_on_email", unique: true, using: :btree
|
||||||
|
add_index "admins", ["reset_password_token"], name: "index_admins_on_reset_password_token", unique: true, using: :btree
|
||||||
|
|
||||||
create_table "albums", force: true do |t|
|
create_table "albums", force: true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.boolean "super_admin"
|
t.boolean "super_admin"
|
||||||
@ -270,6 +276,16 @@ ActiveRecord::Schema.define(version: 20141209215455) do
|
|||||||
add_index "forum_user_images", ["album_id_id"], name: "index_forum_user_images_on_album_id_id", using: :btree
|
add_index "forum_user_images", ["album_id_id"], name: "index_forum_user_images_on_album_id_id", using: :btree
|
||||||
add_index "forum_user_images", ["forum_user_id"], name: "index_forum_user_images_on_forum_user_id", using: :btree
|
add_index "forum_user_images", ["forum_user_id"], name: "index_forum_user_images_on_forum_user_id", using: :btree
|
||||||
|
|
||||||
|
create_table "forum_user_topic_vieweds", force: true do |t|
|
||||||
|
t.integer "forum_topic_id"
|
||||||
|
t.integer "forum_user_id"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "forum_user_topic_vieweds", ["forum_topic_id"], name: "index_forum_user_topic_vieweds_on_forum_topic_id", using: :btree
|
||||||
|
add_index "forum_user_topic_vieweds", ["forum_user_id"], name: "index_forum_user_topic_vieweds_on_forum_user_id", using: :btree
|
||||||
|
|
||||||
create_table "forum_users", force: true do |t|
|
create_table "forum_users", force: true do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "firstname"
|
t.string "firstname"
|
||||||
|
9
test/fixtures/forum_user_topic_vieweds.yml
vendored
Normal file
9
test/fixtures/forum_user_topic_vieweds.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
forum_topic_id:
|
||||||
|
forum_user_id:
|
||||||
|
|
||||||
|
two:
|
||||||
|
forum_topic_id:
|
||||||
|
forum_user_id:
|
7
test/models/forum_user_topic_viewed_test.rb
Normal file
7
test/models/forum_user_topic_viewed_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ForumUserTopicViewedTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user