revel的.flash和.error

huangapple go评论94阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2014年4月15日 02:34:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/23067607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定