Skip to content

Instantly share code, notes, and snippets.

@evie404
Created August 20, 2013 22:01
Show Gist options
  • Save evie404/6287918 to your computer and use it in GitHub Desktop.
Save evie404/6287918 to your computer and use it in GitHub Desktop.
rails controller with ivar set in private method
class HistoryController < ApplicationController
before_filter :get_history, only: [:show, :edit, :update, :destroy]
def index
@histories = History.all
end
def show
@history = History.find(params[:id])
end
def new
@history = current_user.cosplay_histories.new
end
def edit
end
def create
@history = current_user.cosplay_histories.new(params[:history])
respond_to do |format|
if @history.save
format.html { redirect_to @history, notice: 'History was successfully created.' }
format.json { render json: @history, status: :created, location: @history }
else
format.html { render action: "new" }
format.json { render json: @history.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @history.update_attributes(params[:history])
format.html { redirect_to @history, notice: 'History was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @history.errors, status: :unprocessable_entity }
end
end
end
def destroy
@history.destroy
respond_to do |format|
format.html { redirect_to histories_url }
format.json { head :no_content }
end
end
private
def get_history
@history = History.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment