mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
Fix rails4 stuff
This commit is contained in:
parent
322001f8d3
commit
4a2b4d6c71
14 changed files with 58 additions and 22 deletions
|
@ -21,7 +21,7 @@ class ArticlesController < ApplicationController
|
|||
|
||||
def show
|
||||
raise AccessError unless @article.can_show? cuser
|
||||
@article.read_by! cuser if cuser
|
||||
cuser.mark_as_read(@article) if cuser
|
||||
# @article.record_view_count(request.remote_ip, cuser.nil?)
|
||||
end
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class Article < ActiveRecord::Base
|
|||
after_destroy :remove_readings
|
||||
|
||||
has_view_count
|
||||
acts_as_reader
|
||||
acts_as_readable
|
||||
acts_as_versioned
|
||||
|
||||
non_versioned_columns << 'category_id'
|
||||
|
|
|
@ -48,7 +48,7 @@ class Category < ActiveRecord::Base
|
|||
has_many :gathers
|
||||
has_many :servers
|
||||
|
||||
acts_as_reader
|
||||
acts_as_readable
|
||||
|
||||
def to_s
|
||||
name
|
||||
|
|
|
@ -34,7 +34,7 @@ class Forum < ActiveRecord::Base
|
|||
|
||||
after_create :update_position
|
||||
|
||||
acts_as_reader
|
||||
acts_as_readable
|
||||
|
||||
def to_s
|
||||
self.title
|
||||
|
|
|
@ -35,10 +35,10 @@ class Issue < ActiveRecord::Base
|
|||
belongs_to :author, :class_name => "User"
|
||||
belongs_to :assigned, :class_name => "User"
|
||||
|
||||
scope :unread_by,
|
||||
lambda { |user| {
|
||||
:joins => "LEFT JOIN readings ON readable_type = 'Issue' AND readable_id = issues.id AND readings.user_id = #{user.id}",
|
||||
:conditions => "readings.user_id IS NULL"} }
|
||||
#scope :unread_by,
|
||||
# lambda { |user| {
|
||||
# :joins => "LEFT JOIN readings ON readable_type = 'Issue' AND readable_id = issues.id AND readings.user_id = #{user.id}",
|
||||
# :conditions => "readings.user_id IS NULL"} }
|
||||
scope :with_status, -> (s) { where(status: s) }
|
||||
|
||||
validates_length_of :title, :in => 1..50
|
||||
|
@ -49,7 +49,7 @@ class Issue < ActiveRecord::Base
|
|||
before_save :parse_text
|
||||
after_save :remove_readings
|
||||
|
||||
acts_as_reader
|
||||
acts_as_readable
|
||||
|
||||
def to_s
|
||||
title
|
||||
|
|
|
@ -24,12 +24,12 @@ class Message < ActiveRecord::Base
|
|||
validates_length_of :text, :in => 1..65000
|
||||
|
||||
scope :ordered, :order => "created_at DESC"
|
||||
scope :read_by,
|
||||
lambda { |user| {:include => :readings, :conditions => ["readings.user_id = ?", user.id]} }
|
||||
scope :unread_by,
|
||||
lambda { |user| {
|
||||
:joins => "LEFT JOIN readings ON readable_type = 'Message' AND readable_id = messages.id AND readings.user_id = #{user.id}",
|
||||
:conditions => "readings.user_id IS NULL"} }
|
||||
#scope :read_by,
|
||||
# lambda { |user| {:include => :readings, :conditions => ["readings.user_id = ?", user.id]} }
|
||||
#scope :unread_by,
|
||||
# lambda { |user| {
|
||||
# :joins => "LEFT JOIN readings ON readable_type = 'Message' AND readable_id = messages.id AND readings.user_id = #{user.id}",
|
||||
# :conditions => "readings.user_id IS NULL"} }
|
||||
|
||||
belongs_to :sender, :polymorphic => true
|
||||
belongs_to :recipient, :polymorphic => true
|
||||
|
@ -37,7 +37,7 @@ class Message < ActiveRecord::Base
|
|||
before_save :parse_text
|
||||
after_create :send_notifications
|
||||
|
||||
acts_as_reader
|
||||
acts_as_readable
|
||||
|
||||
def to_s
|
||||
title
|
||||
|
|
|
@ -62,7 +62,7 @@ class Movie < ActiveRecord::Base
|
|||
mount_uploader :picture, MovieUploader
|
||||
|
||||
has_view_count
|
||||
acts_as_reader
|
||||
acts_as_readable
|
||||
|
||||
def to_s
|
||||
file.to_s
|
||||
|
|
|
@ -39,7 +39,7 @@ class Topic < ActiveRecord::Base
|
|||
|
||||
after_create :make_post
|
||||
|
||||
acts_as_reader
|
||||
acts_as_readable
|
||||
|
||||
def self.recent_topics
|
||||
find_by_sql %q{
|
||||
|
|
|
@ -119,6 +119,8 @@ class User < ActiveRecord::Base
|
|||
|
||||
accepts_nested_attributes_for :profile
|
||||
|
||||
acts_as_reader
|
||||
|
||||
acts_as_versioned
|
||||
non_versioned_columns << 'firstname'
|
||||
non_versioned_columns << 'lastname'
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<% category.articles.nodrafts.ordered.each do |article| %>
|
||||
<div class="article-list">
|
||||
<div class="title">
|
||||
<% if cuser and !article.read_by? cuser %>
|
||||
<% if cuser and !cuser.have_read?(article) %>
|
||||
<span class="new">NEW</span>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
<% forums.each do |forum| %>
|
||||
<tr>
|
||||
<td class="bullet <%= 'updated' if cuser and !forum.read_by?(cuser) %>"></td>
|
||||
<td class="bullet <%= 'updated' if cuser and !cuser.have_read?(forum) %>"></td>
|
||||
<td class="forum">
|
||||
<h5><%= namelink(forum) %></h5>
|
||||
<%= forum.description %>
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
<%= form_for @lock do |f| %>
|
||||
<%= f.hidden_field :lockable_type %>
|
||||
<%= f.hidden_field :lockable_id %>
|
||||
<%= link_to_function "Lock", "this.parentNode.submit()", class: 'button' %>
|
||||
<%= link_to "Lock", "#", class: 'button submitButton' %>
|
||||
<% end %>
|
||||
<% elsif @lock.can_destroy? cuser %>
|
||||
<%= link_to 'Unlock', @lock, class: 'button', confirm: 'Are you sure?', method: :delete %>
|
||||
|
|
24
db/migrate/20200315183444_unread_migration.rb
Normal file
24
db/migrate/20200315183444_unread_migration.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class UnreadMigration < Unread::MIGRATION_BASE_CLASS
|
||||
def self.up
|
||||
create_table ReadMark, force: true, options: create_options do |t|
|
||||
t.references :readable, polymorphic: { null: false }
|
||||
t.references :reader, polymorphic: { null: false }
|
||||
t.datetime :timestamp
|
||||
end
|
||||
|
||||
add_index ReadMark, [:reader_id, :reader_type, :readable_type, :readable_id], name: 'read_marks_reader_readable_index', unique: true
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table ReadMark
|
||||
end
|
||||
|
||||
def self.create_options
|
||||
options = ''
|
||||
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) \
|
||||
&& ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
||||
options = 'DEFAULT CHARSET=latin1'
|
||||
end
|
||||
options
|
||||
end
|
||||
end
|
12
db/schema.rb
12
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20200315144657) do
|
||||
ActiveRecord::Schema.define(version: 20200315183444) do
|
||||
|
||||
create_table "article_versions", force: true do |t|
|
||||
t.integer "article_id"
|
||||
|
@ -633,6 +633,16 @@ ActiveRecord::Schema.define(version: 20200315144657) do
|
|||
add_index "ratings", ["rate_id"], name: "index_ratings_on_rate_id", using: :btree
|
||||
add_index "ratings", ["rateable_id", "rateable_type"], name: "index_ratings_on_rateable_id_and_rateable_type", using: :btree
|
||||
|
||||
create_table "read_marks", force: true do |t|
|
||||
t.integer "readable_id"
|
||||
t.string "readable_type", null: false
|
||||
t.integer "reader_id"
|
||||
t.string "reader_type", null: false
|
||||
t.datetime "timestamp"
|
||||
end
|
||||
|
||||
add_index "read_marks", ["reader_id", "reader_type", "readable_type", "readable_id"], name: "read_marks_reader_readable_index", unique: true, using: :btree
|
||||
|
||||
create_table "readings", force: true do |t|
|
||||
t.string "readable_type"
|
||||
t.integer "readable_id"
|
||||
|
|
Loading…
Reference in a new issue