class FrogsController < ApplicationController
before_action :find_frog, only: [:edit, :update, :show, :destroy]
after_action :redirect_home, only: [:update, :create, :destroy]
def index
@frogs = Frog.all
end
def new
@ponds = Pond.all
@frog = Frog.new
end
def create
@frog = Frog.create(frog_params)
end
def edit
@ponds = Pond.all
end
def update
@frog.update_attributes(frog_params)
end
def show
end
def destroy
@frog.destroy
end
private
def find_frog
@frog = Frog.find(params[:id])
end
def frog_params
params.require(:frog).permit(:name, :color, :pond_id)
end
def redirect_home
redirect_to frogs_path
end
end
Hi all. I was wondering if someone could explain to me why the update route in rails can't take my after_action of redirecting (custom made method on the bottom) it home. The error that I get when i include update in the after_action is "Missing template frogs/update". This is going to cause me to manually add a redirect_to frogs_path inside the update method.
thanks!
The after_action
callback is triggered after the action has run its course. You cannot use it to render or redirect. Do that within the action itself by calling the method:
def update
...
redirect_home
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With