diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2015-02-25 18:47:09 -0800 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2015-02-25 18:47:09 -0800 |
commit | 4e94e31aa0acda54ae962840b57ae42ca6e71185 (patch) | |
tree | 19fa5fdc8c3bea56fb93463508a81514acd0f604 /app/controllers/downloads_controller.rb | |
parent | f031bdc3e5214c699123830d8cc9f9309b792a68 (diff) |
rails generate scaffold Download
Diffstat (limited to 'app/controllers/downloads_controller.rb')
-rw-r--r-- | app/controllers/downloads_controller.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb new file mode 100644 index 0000000..300d0b1 --- /dev/null +++ b/app/controllers/downloads_controller.rb @@ -0,0 +1,74 @@ +class DownloadsController < ApplicationController + before_action :set_download, only: [:show, :edit, :update, :destroy] + + # GET /downloads + # GET /downloads.json + def index + @downloads = Download.all + end + + # GET /downloads/1 + # GET /downloads/1.json + def show + end + + # GET /downloads/new + def new + @download = Download.new + end + + # GET /downloads/1/edit + def edit + end + + # POST /downloads + # POST /downloads.json + def create + @download = Download.new(download_params) + + respond_to do |format| + if @download.save + format.html { redirect_to @download, notice: 'Download was successfully created.' } + format.json { render :show, status: :created, location: @download } + else + format.html { render :new } + format.json { render json: @download.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /downloads/1 + # PATCH/PUT /downloads/1.json + def update + respond_to do |format| + if @download.update(download_params) + format.html { redirect_to @download, notice: 'Download was successfully updated.' } + format.json { render :show, status: :ok, location: @download } + else + format.html { render :edit } + format.json { render json: @download.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /downloads/1 + # DELETE /downloads/1.json + def destroy + @download.destroy + respond_to do |format| + format.html { redirect_to downloads_url, notice: 'Download was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_download + @download = Download.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def download_params + params.require(:download).permit(:name, :filename, :type, :description, :hits) + end +end |