Last active
December 21, 2017 17:20
-
-
Save ElMassimo/18fbdb7108f46f3c975712945f7a3318 to your computer and use it in GitHub Desktop.
Sample Rails CRUD Controller
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 BandController < ApplicationController | |
def new | |
@band = Band.new | |
end | |
def create | |
@band = Band.new(band_params) | |
if @band.save | |
redirect_to(@band) | |
else | |
render :new | |
end | |
end | |
def edit | |
@band = Band.find(params[:id]) | |
end | |
def update | |
@band = Band.find(params[:id]) | |
if @band.update_attributes(person_params) | |
redirect_to(@band) | |
else | |
render :edit | |
end | |
end | |
def destroy | |
@band = Band.find(params[:id]) | |
@band.destroy | |
redirect_to bands_path | |
end | |
private | |
def band_params | |
params.require(:band).permit(:name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment