Ric*_*wis 4 ruby alert sinatra
我试图在成功提交表格后出现闪光通知.在Rails中我会在控制器中使用这样的东西:
:notice => "Youve submitted the form"
Run Code Online (Sandbox Code Playgroud)
我遇到了Sinatra flash gem,想在重定向后显示flash消息.我像这样安装了gem和setup:
myapp.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
Run Code Online (Sandbox Code Playgroud)
所有这一切都是我被重定向到没有flash消息的索引页面.看看文档,这是我能看到的,我需要做的.有人看到有什么不同吗?
我在重定向之前移动了我的flash通知,因此它可以保存消息:
flash[:notice] = "Thanks for your email. I'll be in touch soon."
redirect '/success'
get('/success') do
erb :index
end
Run Code Online (Sandbox Code Playgroud)
然后,在我看来,我现在把它放在顶部:
<div id='flash' class='notice'>
<a class="close" data-dismiss="alert">×</a>
<%= flash[:notice] %>
</div>
Run Code Online (Sandbox Code Playgroud)
它需要一些造型但是有效.如果有人有更好的解决方案,请分享.
| 归档时间: |
|
| 查看次数: |
2414 次 |
| 最近记录: |