我正在尝试在成功提交表单后显示一条闪现通知。在 Rails 中,我会在 Controller 中使用类似这样的东西:
:notice => "Youve submitted the form"
我遇到了 Sinatra flash gem 并希望在重定向后显示一条 flash 消息。我像这样安装了 gem 和设置:
我的应用.rb:
require 'sinatra/flash'
enable :sessions
#form config
)}
redirect '/success' # this is the hook after my form submission
end
get('/success') do
flash[:success] = "Thanks for your email. I'll be in touch soon."
erb :index
end
所发生的只是我被重定向到没有任何闪现消息的索引页面。查看文档,这就是我所看到的我需要做的。有没有人看到任何不同之处?
最佳答案
我将 flash notice 移动到重定向之前,以便它可以保存消息:
flash[:notice] = "Thanks for your email. I'll be in touch soon."
redirect '/success'
get('/success') do
erb :index
end
然后,在我看来,我暂时将其放在顶部:
<div id='flash' class='notice'>
<a class="close" data-dismiss="alert">×</a>
<%= flash[:notice] %>
</div>
它需要一些样式但可以工作。如果有人有更好的解决方案,请分享。
关于ruby - 无法让 Sinatra Flash Gem 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14753782/