1

Im hoping there is a cleaning way of getting flash messages to work in an ajax call using React. Been looking on the web and, honestly, Im sure it can be done without much added code.

def my_method
 [...]

 flash[:success] = "Yea bouy."
 if request.xhr?
    render :json => {
                        :order => true,
                    }
 end
end

I'm not doing a page redirect and was wondering how to get a simple flash to show. Anwers around showing adding more methods. Could I have the flash code within my method? Something like:

def my_method
 [...]
 if request.xhr?
    render :json => {
                        :order => true,
                    }
 end
 return flash[:success] = "Yea bouy." # Only works when page refreshes.
end
Community
  • 1
  • 1
Sylar
  • 11,422
  • 25
  • 93
  • 166

1 Answers1

0

Flash works on page reload, so in case of an Ajax request you can send the message back as a response and show it using JS. Or, you can render a js.erb template and inside that show the message using JS.

Hope that helps!

Rajdeep Singh
  • 17,621
  • 6
  • 53
  • 78