Class: PictureFilesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/picture_files_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /picture_files POST /picture_files.json



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/picture_files_controller.rb', line 79

def create
  @picture_file = PictureFile.new(picture_file_params)

  respond_to do |format|
    if @picture_file.save
      format.html { redirect_to @picture_file, notice: t('controller.successfully_created', model: t('activerecord.models.picture_file')) }
      format.json { render json: @picture_file, status: :created, location: @picture_file }
    else
      format.html { render action: "new" }
      format.json { render json: @picture_file.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /picture_files/1 DELETE /picture_files/1.json



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'app/controllers/picture_files_controller.rb', line 131

def destroy
  attachable = @picture_file.picture_attachable
  @picture_file.destroy

  respond_to do |format|
    flash[:notice] = t('controller.successfully_deleted', model: t('activerecord.models.picture_file'))
    format.html {
      case attachable.class.name
      when 'Manifestation'
        redirect_to picture_files_url(manifestation_id: attachable.id)
      when 'Agent'
        redirect_to picture_files_url(agent_id: attachable.id)
      when 'Shelf'
        redirect_to picture_files_url(shelf_id: attachable.id)
      else
        if defined?(EnjuEvent)
          if attachable.class.name == 'Event'
            redirect_to picture_files_url(event_id: attachable.id)
          else
            redirect_to picture_files_url
          end
        else
          redirect_to picture_files_url
        end
      end
    }
    format.json { head :no_content }
  end
end

#editObject

GET /picture_files/1/edit



74
75
# File 'app/controllers/picture_files_controller.rb', line 74

def edit
end

#indexObject

GET /picture_files GET /picture_files.json



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/picture_files_controller.rb', line 9

def index
  if @attachable
    @picture_files = @attachable.picture_files.attached.page(params[:page])
  else
    @picture_files = PictureFile.attached.page(params[:page])
  end

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @picture_files }
  end
end

#newObject

GET /picture_files/new GET /picture_files/new.json



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/picture_files_controller.rb', line 58

def new
  unless @attachable
    redirect_to picture_files_url
    return
  end
  #raise unless @event or @manifestation or @shelf or @agent
  @picture_file = PictureFile.new
  @picture_file.picture_attachable = @attachable

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @picture_file }
  end
end

#showObject

GET /picture_files/1 GET /picture_files/1.json



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/picture_files_controller.rb', line 24

def show
  case params[:size]
  when 'original'
    size = 'original'
  when 'thumb'
    size = 'thumb'
  else
    size = 'medium'
  end

  if @picture_file.picture.exists?
    if ENV['ENJU_STORAGE'] == 's3'
      file = Faraday.get(@picture_file.picture.expiring_url).body.force_encoding('UTF-8')
    else
      file = @picture_file.picture.path(size.to_sym)
    end
  end

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @picture_file }
    format.html.phone {
      if params[:format] == 'download'
        render_image(file)
      end
    }
    format.download {
      render_image(file)
    }
  end
end

#updateObject

PUT /picture_files/1 PUT /picture_files/1.json



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/picture_files_controller.rb', line 95

def update
  # 並べ替え
  if params[:move]
    move_position(@picture_file, params[:move], false)
    case
    when @picture_file.picture_attachable.is_a?(Shelf)
      redirect_to picture_files_url(shelf_id: @picture_file.picture_attachable_id)
    when @picture_file.picture_attachable.is_a?(Manifestation)
      redirect_to picture_files_url(manifestation_id: @picture_file.picture_attachable_id)
    else
      if defined?(EnjuEvent)
        if @picture_file.picture_attachable.is_a?(Event)
          redirect_to picture_files_url(manifestation_id: @picture_file.picture_attachable_id)
        else
          redirect_to picture_files_url
        end
      else
        redirect_to picture_files_url
      end
    end
    return
  end

  respond_to do |format|
    if @picture_file.update(picture_file_params)
      format.html { redirect_to @picture_file, notice: t('controller.successfully_updated', model: t('activerecord.models.picture_file')) }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @picture_file.errors, status: :unprocessable_entity }
    end
  end
end