Method: SubjectsController#create

Defined in:
app/controllers/subjects_controller.rb

#createObject

POST /subjects POST /subjects.json



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/controllers/subjects_controller.rb', line 119

def create
  if @work
    @subject = @work.subjects.new(params[:subject])
  else
    @subject = Subject.new(params[:subject])
  end
  classification = Classification.find(@subject.classification_id) if @subject.classification_id.present?
  subject_heading_type = SubjectHeadingType.find(@subject.subject_heading_type_id) if @subject.subject_heading_type_id.present?

  respond_to do |format|
    if @subject.save
      #@subject.classifications << classification if classification
      @subject.subject_heading_types << subject_heading_type if subject_heading_type
#        @subject.subject_heading_type = subject_heading_type if subject_heading_type
      format.html { redirect_to @subject, :notice => t('controller.successfully_created', :model => t('activerecord.models.subject')) }
      format.json { render :json => @subject, :status => :created, :location => @subject }
    else
      @classification = classification
      @subject_heading_type = subject_heading_type
      prepare_options
      format.html { render :action => "new" }
      format.json { render :json => @subject.errors, :status => :unprocessable_entity }
    end
  end
end