4

我试图在成功提交表单后显示一个快速通知。在 Rails 中,我会在控制器中使用类似的东西:

:notice => "Youve submitted the form"

我遇到了Sinatra flash gem,想在重定向后显示一条 flash 消息。我像这样安装了gem和设置:

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

所发生的一切是我被重定向到没有 Flash 消息的索引页面。查看文档,这就是我需要做的所有事情。有没有人看到有什么不同?

4

1 回答 1

5

我将我的 Flash 通知移到重定向之前,以便它可以保存消息:

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">&#215;</a>
 <%= flash[:notice] %>
</div>

它需要一些样式,但可以工作。如果有人有更好的解决方案,请分享。

于 2013-02-07T15:52:11.727 回答