英文:
revel's .flash and .error
问题
我安装了预订应用程序并自己构建了一个小应用程序,但两者都无法显示闪存错误,就像这里所示:
https://github.com/revel/revel/blob/master/samples/booking/app/views/hotels/settings.html
我在自己的应用程序中使用的示例视图是https://gist.github.com/daemonfire300/10581488,并且对.error进行迭代工作得很好。
我是否漏掉了什么?
英文:
I installed the booking app and build a small app by myself and both suffer from the inability of displaying flash errors as shown here:
https://github.com/revel/revel/blob/master/samples/booking/app/views/hotels/settings.html
The example view I use in my own app is https://gist.github.com/daemonfire300/10581488 and iterating over .error works perfectly fine.
Am I missing something?
答案1
得分: 1
我写了一个类似这样的控制器(请注意,我使用的是默认的 App,而不是你在示例中使用的 UserController):
type User struct {
Username string
Password string
Email string
}
func (c App) Register(user User) revel.Result {
c.Validation.Required(user.Username).Message("缺少用户名")
c.Validation.Required(user.Password).Message("缺少密码")
c.Validation.Required(user.Email).Message("缺少电子邮件")
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
}
return c.Redirect(App.Index)
}
当我在表单中漏掉一个字段(例如密码),我确实会得到错误提示,并且所有先前字段的值都会被恢复,如此所示。
英文:
I wrote a controller like this (please note that I used the default App instead of the UserController that you use in your example):
type User struct {
Username string
Password string
Email string
}
func (c App) Register(user User) revel.Result {
c.Validation.Required(user.Username).Message("Missing username")
c.Validation.Required(user.Password).Message("Missing password")
c.Validation.Required(user.Email).Message("Missing email")
if c.Validation.HasErrors() {
c.Validation.Keep()
c.FlashParams()
}
return c.Redirect(App.Index)
}
When I miss a field on the form (for example the password), I do get the errors and all previous fields' values are restored, as shown here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论