Add support for strong params

pull/6827/head
Mohamed Wael Khobalatte 9 years ago
parent 7ad5e8d50b
commit 2f10c30828
  1. 11
      app/controllers/documents_controller.rb
  2. 5
      app/models/document.rb

@ -61,12 +61,12 @@ class DocumentsController < ApplicationController
def new def new
@document = @project.documents.build @document = @project.documents.build
@document.safe_attributes = params[:document] @document.attributes = document_params
end end
def create def create
@document = @project.documents.build @document = @project.documents.build
@document.safe_attributes = params[:document] @document.attributes = document_params
if @document.save if @document.save
attachments = Attachment.attach_files(@document, params[:attachments]) attachments = Attachment.attach_files(@document, params[:attachments])
render_attachment_warning_if_needed(@document) render_attachment_warning_if_needed(@document)
@ -82,7 +82,7 @@ class DocumentsController < ApplicationController
end end
def update def update
@document.safe_attributes = params[:document] @document.attributes = document_params
if @document.save if @document.save
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'show', :id => @document redirect_to :action => 'show', :id => @document
@ -108,4 +108,9 @@ class DocumentsController < ApplicationController
end end
redirect_to :action => 'show', :id => @document redirect_to :action => 'show', :id => @document
end end
private
def document_params
params.require(:document).permit('category_id', 'title', 'description')
end
end end

@ -31,7 +31,6 @@
#++ #++
class Document < ActiveRecord::Base class Document < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :project belongs_to :project
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
acts_as_attachable :delete_permission => :manage_documents acts_as_attachable :delete_permission => :manage_documents
@ -66,10 +65,6 @@ class Document < ActiveRecord::Base
after_initialize :set_default_category after_initialize :set_default_category
attr_accessible :title, :description, :project, :category, :category_id
safe_attributes 'category_id', 'title', 'description'
def visible?(user=User.current) def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_documents, project) !user.nil? && user.allowed_to?(:view_documents, project)
end end

Loading…
Cancel
Save