##// END OF EJS Templates
set default category_id instead of the object (#11665)...
set default category_id instead of the object (#11665) Rails 2.3 still has issues with synchronizing the association_id and association attributes of an object. That means, if you set the association with an object first and then just set the id afterwards, the object wins and the setting of the id gets lost. This is not an issue in Rails >= 3.1 anymore. Contributed by Holger Just. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@10226 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r10043:14dcefaa97f9
r10043:14dcefaa97f9
Show More
document.rb
58 lines | 2.3 KiB | text/x-ruby | RubyLexer
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674 # RedMine - project management software
# Copyright (C) 2006-2011 Jean-Philippe Lang
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674 #
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674 #
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Document < ActiveRecord::Base
Jean-Philippe Lang
Prevent mass-assignment when adding/updating a document (#10390)....
r9010 include Redmine::SafeAttributes
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330 belongs_to :project
Eric Davis
Changed Enumerations to use a Single Table Inheritance...
r2677 belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
Jean-Philippe Lang
AttachmentsController now handles attachments deletion....
r2114 acts_as_attachable :delete_permission => :manage_documents
Jean-Philippe Lang
added svn:eol-style native property on /app files...
r330
Jean-Philippe Lang
Ability to search all projects or the projects the user belongs to (#791)....
r1420 acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
Jean-Philippe Lang
Search engines now supports pagination....
r755 acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
Jean-Philippe Lang
Fixed: error on activity page when displaying a document (undefined method 'author')....
r883 :author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil },
Jean-Philippe Lang
Search engines now supports pagination....
r755 :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
Jean-Philippe Lang
Activity refactoring....
r1692 acts_as_activity_provider :find_options => {:include => :project}
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674
Jean-Philippe Lang
0.3 unstable...
r10 validates_presence_of :project, :title, :category
Jean-Philippe Lang
Added several validates_length_of...
r590 validates_length_of :title, :maximum => 60
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674
Jean-Philippe Lang
Adds visible scope to redmine links queries....
r4639 named_scope :visible, lambda {|*args| { :include => :project,
Jean-Philippe Lang
Makes visible scopes accept projects option and deprecate Project.visible_by....
r5204 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_documents, *args) } }
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674
Jean-Philippe Lang
Prevent mass-assignment when adding/updating a document (#10390)....
r9010 safe_attributes 'category_id', 'title', 'description'
Jean-Philippe Lang
Make sure users don't get notified for thing they can not view (#3589)....
r3055 def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_documents, project)
end
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674
Jean-Philippe Lang
Removed after_initialize methods....
r8168 def initialize(attributes=nil, *args)
super
Jean-Philippe Lang
Fixed: default category ignored when adding a document (#2328)....
r2122 if new_record?
Toshi MARUYAMA
set default category_id instead of the object (#11665)...
r10043 # Rails3 use this instead
# self.category ||= DocumentCategory.default
self.category_id = DocumentCategory.default.id if self.category_id == 0
Jean-Philippe Lang
Fixed: default category ignored when adding a document (#2328)....
r2122 end
end
Toshi MARUYAMA
remove trailing white-spaces from Document model source....
r5674
Jean-Philippe Lang
Show last update datetime (last attachment added) on document list (#4232)....
r2981 def updated_on
unless @updated_on
Jean-Philippe Lang
Order is already defined on attachments association....
r8338 a = attachments.last
Jean-Philippe Lang
Show last update datetime (last attachment added) on document list (#4232)....
r2981 @updated_on = (a && a.created_on) || created_on
end
@updated_on
end
Jean-Philippe Lang
Initial commit...
r2 end