Files
danbooru/app/models/post_event.rb
evazion 47ecf034a7 /posts/:id/events - fix exception when viewed by mod.
NoMethodError exception raised

    undefined method `creator' for #<PostEvent:0x007f9a298e64d8> Did you mean? creator_id
    app/views/post_events/index.html.erb:23:in `block in _app_views_post_events_index_html_erb__2088986421112502721_70150054247640'
    app/views/post_events/index.html.erb:18:in `each'
    app/views/post_events/index.html.erb:18:in `_app_views_post_events_index_html_erb__2088986421112502721_70150054247640'
    app/controllers/post_events_controller.rb:6:in `index'
2017-03-21 17:17:18 -05:00

37 lines
696 B
Ruby

class PostEvent
include ActiveModel::Model
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
attr_accessor :event
delegate :creator, :creator_id, :reason, :is_resolved, :created_at, to: :event
def self.find_for_post(post_id)
post = Post.find(post_id)
(post.appeals + post.flags).sort_by(&:created_at).reverse.map { |e| new(event: e) }
end
def type_name
case event
when PostFlag
"flag"
when PostAppeal
"appeal"
end
end
def type
type_name.first
end
def attributes
{
"creator_id": nil,
"created_at": nil,
"reason": nil,
"is_resolved": nil,
"type": nil,
}
end
end