Module: RecordsControllerBehavior

Included in:
RecordsController
Defined in:
app/controllers/concerns/records_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/concerns/records_controller_behavior.rb', line 19

def create
  authorize! :create, ActiveFedora::Base
  unless has_valid_type?
    redirect_to hydra_editor.new_record_path, :flash=> {error: "Lost the type"}
    return
  end
  @record = params[:type].constantize.new
  set_attributes

  respond_to do |format|
    if @record.save
      format.html { redirect_to main_app.catalog_path(@record), notice: 'Object was successfully created.' }
      # ActiveFedora::Base#to_json causes a circular reference.  Do somethign easy
      data = @record.terms_for_editing.inject({}) { |h,term|  h[term] = @record[term]; h } 
      format.json { render json: data, status: :created, location: hydra_editor.record_path(@record) }
    else
      format.html { render action: "new" }
      format.json { render json: @record.errors, status: :unprocessable_entity }
    end
  end

end

#editObject



13
14
15
16
17
# File 'app/controllers/concerns/records_controller_behavior.rb', line 13

def edit
  @record = ActiveFedora::Base.find(params[:id], cast: true)
  authorize! :edit, @record
  initialize_fields
end

#newObject



2
3
4
5
6
7
8
9
10
11
# File 'app/controllers/concerns/records_controller_behavior.rb', line 2

def new
  authorize! :create, ActiveFedora::Base
  unless has_valid_type?
    render 'choose_type'
    return
  end

  @record = params[:type].constantize.new
  initialize_fields
end

#updateObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/concerns/records_controller_behavior.rb', line 42

def update
  @record = ActiveFedora::Base.find(params[:id], cast: true)
  authorize! :update, @record
  set_attributes
  respond_to do |format|
    if @record.save
      format.html { redirect_to main_app.catalog_path(@record), notice: 'Object was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @record.errors, status: :unprocessable_entity }
    end
  end
end