Create on loop
# avo-2
r
Hi there, currently adding avohq to build an admin portal, looking good so far! I'll be using it to input a lot of data. Is there a way to stay on the "create" page after adding a new record? I'm losing a lot of time having to click on "Create new item" again. I found this: https://docs.avohq.io/2.0/resources.html#customize-what-happens-after-a-record-is-created-edited but it looks like I can't redirect to the "new" page
l
Hi @rapid-psychiatrist-19805 we're happy to know that you're having a good experience with Avo. That kind of behavior is perfectly achievable. The
after_create_path
option on the resource only accept
:show
(default),
:edit
, or
:index
. However there is another approach to handle this. We let there some hooks on the controllers (I recommend to give a quick view on all of them here https://docs.avohq.io/2.0/controllers.html). There is several hooks that you can use to achieve the wanted behavior, for example if you want to get more control over the response after a record creation you can override the
create_success_action
(https://docs.avohq.io/2.0/controllers.html#create_success_action) Something like this (I'll use the
post
model on my examples)
Copy code
ruby
class Avo::PostsController < Avo::ResourcesController
  def create_success_action
    respond_to do |format|
      format.html { redirect_to new_resources_post_path, notice: create_success_message}
    end
  end
end
Notice that the only thing that I changed was the path from the redirect, if you don't want to change the action but only the path there is actually another hook,
after_create_path
(https://docs.avohq.io/2.0/controllers.html#after_create_path)
Copy code
ruby
class Avo::PostsController < Avo::ResourcesController
  def after_create_path
    new_resources_post_path
  end
end
TL;DR In the avo controller hook into the
after_create_path
overriding that method and returning the resource creation page
r
Thank you! Unfortunately it doesn't look like it's loading the controller properly, maybe a autoloader issue on my side, i'll investigate
l
Hmm, let me know if I can help
r
Yeah nevermind I didn't notice I wasn't on localhost 😂 early morning mistake
It works, thanks!
l
Anytime!
l
I would merge a PR about an option of the resource where
self.create_and_another = true
option that would add a button like that to a resource 💪