Created
April 3, 2017 10:49
-
-
Save ElMassimo/6775148c0d7364be111531a254b41ba9 to your computer and use it in GitHub Desktop.
Rails CRUD Controller using Draper
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.decorate | |
end | |
def create | |
@band = Band.new(band_params) | |
if @band.save | |
redirect_to(@band) | |
else | |
@band = @band.decorate | |
render :new | |
end | |
end | |
def edit | |
@band = Band.find(params[:id]).decorate | |
end | |
def update | |
@band = Band.find(params[:id]) | |
if @band.update_attributes(band_params) | |
redirect_to(@band) | |
else | |
@band = @band.decorate | |
render :edit | |
end | |
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