-
Notifications
You must be signed in to change notification settings - Fork 0
RailsController
Tim edited this page Aug 12, 2015
·
5 revisions
Code to include within the controller modules.
###code A before action allows us to run some code before each other module has been done, this is good to return some data from active record or to check some authorization.
before_action :<function>, only: [:edit, :update, :destroy]
def <function>
@<entity> = <Enitity>.find(params[:id])
# check authorisiation
end###code for apis
def show
@zombie = Zombie.find(params[:id])
respond_to do |format|
format.xml {render json: @zombie }
end
end###Directing to views
render action: '<viewname>' this is going to map to the view called status.html.erb
redirect_to(<path>) or
`redirect_to(, notice: "sorry can't do that")