app/controllers/docs_controller.rb
# POST /docs
# POST /docs.json
# Creation of document is only allowed for single division documents.
POST /docs
POST /docs.json
Creation of document is only allowed for single division documents.
POST / docs POST / docs . json Creation of document is only allowed for single division documents .
def create
		begin
			raise ArgumentError, "project id has to be specified." unless params[:project_id].present?
			@project = Project.editable(current_user).find_by_name(params[:project_id])
			raise "The project does not exist, or you are not authorized to make a change to the project.\n" unless @project.present?
			doc_hash = if doc_params.present? && params[:commit].present?
				doc_params
			else
				text = if params[:text]
					params[:text]
				elsif request.content_type =~ /text/
					request.body.read
				end
				raise "Could not find text." unless text.present?
				_doc = {
					source: params[:source],
					sourcedb: params[:sourcedb] || '',
					sourceid: params[:sourceid],
					body: text
				}
				_doc[:divisions] = params[:divisions] if params[:divisions].present?
				_doc[:typesettings] = params[:typesettings] if params[:typesettings].present?
				_doc
			end
			doc_hash = Doc.hdoc_normalize!(doc_hash, current_user, current_user.root?)
			docs_saved, messages = Doc.store_hdocs([doc_hash])
			raise IOError, "Could not create the document: #{messages.join("\n")}" if messages.present?
			@doc = docs_saved.first
			@doc.projects << @project
			expire_fragment("sourcedb_counts_#{@project.name}")
			expire_fragment("count_docs_#{@project.name}")
			expire_fragment("count_#{@doc.sourcedb}_#{@project.name}")
			respond_to do |format|
				format.html { redirect_to show_project_sourcedb_sourceid_docs_path(@project.name, doc_hash[:sourcedb], doc_hash[:sourceid]), notice: t('controllers.shared.successfully_created', :model => t('activerecord.models.doc')) }
				format.json { render json: @doc.to_hash, status: :created, location: @doc }
			end
		rescue => e
			respond_to do |format|
				format.html { redirect_to new_project_doc_path(@project.name), notice: e.message }
				format.json { render json: {message: e.message}, status: :unprocessable_entity }
			end
		end
	end
def create begin raise ArgumentError , "project id has to be specified." unless params [ :project_id ] . present? @project = Project . editable ( current_user ) . find_by_name ( params [ :project_id ] ) raise "The project does not exist, or you are not authorized to make a change to the project.\n" unless @project . present? doc_hash = if doc_params . present? && params [ :commit ] . present? doc_params else text = if params [ :text ] params [ :text ] elsif request . content_type =~ / text / request . body . read end raise "Could not find text." unless text . present? _doc = { source : params [ :source ] , sourcedb : params [ :sourcedb ] || '' , sourceid : params [ :sourceid ] , body : text } _doc [ :divisions ] = params [ :divisions ] if params [ :divisions ] . present? _doc [ :typesettings ] = params [ :typesettings ] if params [ :typesettings ] . present? _doc end doc_hash = Doc . hdoc_normalize! ( doc_hash , current_user , current_user . root? ) docs_saved , messages = Doc . store_hdocs ( [ doc_hash ] ) raise IOError , "Could not create the document: #{messages.join("\n")}" if messages . present? @doc = docs_saved . first @doc . projects << @project expire_fragment ( "sourcedb_counts_#{@project.name}" ) expire_fragment ( "count_docs_#{@project.name}" ) expire_fragment ( "count_#{@doc.sourcedb}_#{@project.name}" ) respond_to do | format | format . html { redirect_to show_project_sourcedb_sourceid_docs_path ( @project . name , doc_hash [ :sourcedb ] , doc_hash [ :sourceid ] ) , notice : t ( 'controllers.shared.successfully_created' , :model => t ( 'activerecord.models.doc' ) ) } format . json { render json : @doc . to_hash , status : :created , location : @doc } end rescue => e respond_to do | format | format . html { redirect_to new_project_doc_path ( @project . name ) , notice : e . message } format . json { render json : { message : e . message } , status : :unprocessable_entity } end end end
POST /docs
POST /docs.json
Creation of document is only allowed for single division documents.
POST / docs POST / docs . json Creation of document is only allowed for single division documents .