I’m trying to render only a flash message without a redirect or render after a Create action:
def create
@subscriber = Subscriber.new(params[:subscriber])
if @subscriber.save
success = true
message = "Thanks!"
else
success = false
message = "Sorry, there was an error."
end
respond_to do |format|
format.html {
if success
flash[:success] = message
else
flash[:error] = message
end
}
end
end
With this code I get a Template Missing error. I don’t want to refresh the same page either. How do I show the flash message without refreshing the page and without getting the template error?
When you don’t redirect_to any other action, then you should have a view named
create.htmlThe common practice here is to redirect somewhere like root_path, or to subscriber profile or whatever
And yes, to show just flash message, you could use AJAX, then you controller action will look smth like: