I'm trying to render a js alert directly after a user clicks on a submit.
Here's what I have and what I've tried:
That's my erb file.
<form action="/welcome/subscribe">
<div>
<div id="bottomm">
<input id="bottom" type="text" name="email" placeholder="Adresse mail" />
</div>
<div>
<input type="submit" value="Ok"/>
</div>
</div>
</form>
Here's the subscribe method in my controller:
def subscribe
@test = Test.new
@test.email = params['email']
@test.save
binding.pry
render js: "alert('test)";
end
But I get this error:
Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding.
Any idea? :/
edit:
By adding theses 2 lines I can now avoid the warning:
protect_from_forgery with: :exception
skip_before_action :verify_authenticity_token
But now it's redirecting me on a blank page with just written on it:
alert('test')
subscribe.js.erbfile which does the alert?subscribe.js.erb? But if I do this it will redirect and I'd like to stay on the same page but just print out an alert. Is that posible?