Last active
August 29, 2015 14:01
-
-
Save davidpaulhunt/4b54cd37e5e2ca94864b to your computer and use it in GitHub Desktop.
A simple photo model controller with complete CRUD.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Photo < ActiveRecord::Base | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PhotosController < ApplicationController | |
def new | |
@new_photo = Photo.new | |
end | |
def create | |
@new_photo = Photo.new(photo_params) | |
if @new_photo.save | |
redirect_to photos_path | |
else | |
render :new | |
end | |
end | |
def index | |
@photos = Photo.all | |
end | |
def show | |
@photo = Photo.find(params[:id]) | |
end | |
def edit | |
@photo = Photo.find(params[:id]) | |
end | |
def update | |
@photo = Photo.find(params[:id]) | |
if @photo.update(photo_params) | |
redirect_to photo_path | |
else | |
render :edit | |
end | |
end | |
def destroy | |
@photo = Photo.find(params[:id]) | |
if @photo.destroy | |
redirect_to photos_path | |
else | |
render :show | |
end | |
end | |
private | |
def photo_params | |
params.require(:photo).permit! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment