我做了什麼:)?在rails窗體中有f.error_messages alwais爲空。我如何修復/檢查這個? THXRails f.error_messages alwais empty
1
A
回答
1
的AR#validate方法填充模型的誤差散驗證錯誤。
如果在實例化模型和調用f.error_messages之間沒有調用驗證(通過AR#save或直接),@errors散列永遠不會被填充,並且錯誤從不顯示)。
此外請確保您不重定向(驗證的對象會丟失,並且創建新的對象並且沒有「已填充」的@errors散列),但請致電
1
你是否在尋找error_messages_for:模型?
驗證後,該功能將建立自己的錯誤消息的列表視圖。
例如:
# users_controller.rb
def create
@user = User.new(params[:user])
if @user.save
redirect_to @user
else
render :action => 'new'
end
end
# view/users/new.html.erb
<%= error_messages_for :user %>
<% form_for @user do |f| %>
...
<% end %>
相關問題
- 1. f.error_messages用Rails 3.0
- 2. Ruby on Rails - f.error_messages沒有顯示出來
- 3. rails controller.controller_name empty
- 4. ArgumentError「interning empty string」Rails
- 5. rails form validation empty filed
- 6. rails 5,remote:true form empty data
- 7. Rails選擇Empty方法?
- 8. Rails錯誤不在f.error_messages中顯示,但在錯誤他們是
- 9. Empty cells are moving around when empty
- 10. Android listview with empty lines when empty
- 11. DEPRECATION警告:f.error_messages已從Rails中刪除,現在可作爲插件使用
- 12. ImageView empty
- 13. Text_area empty
- 14. Android:Email'to'field empty
- 15. DropDownList empty
- 16. REMOTE_USER empty
- 17. Empty IQueryable在Empty時返回什麼?
- 18. f.error_messages僅顯示底部的第一條錯誤消息
- 19. Ruby String Object Empty or Not?
- 20. Asp.net MVC2 ModelBindingContext.ModelName empty
- 21. ListView - SimpleCursorAdapter - @android:id/empty
- 22. OpenCV FindContours return empty
- 23. NSPredicate returns empty array
- 24. Delphi textfile empty
- 25. Empty Burndown圖表
- 26. php $ _GET empty
- 27. php isset,empty,null,=「」
- 28. Empty While loop- Arduino
- 29. php class _Construct empty
- 30. CSS float empty spaces