ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2009年1月12日 星期一
some tips, add_to_base, save_with_validation, verify
save_with_validation(perform_validation = true)
The validation process on save can be skipped by passing false. The regular Base#save method is replaced with this when the validations module is mixed in, which it is by default
errors.add_to_base
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/e045ec1dead1ff06
The "save" and "valid?" methods call errors.clear
before running, which was dumping the errors I had added.
Should have thought to put it in the model anyway, it is business
logic after all. This works:
def validate
if items.empty?
errors.add_to_base("Must select at least one item.")
end
end
http://api.rubyonrails.org/classes/ActionController/Verification/ClassMethods.html#M000353
verify :params => "post", :session => "post", "flash" => "note",
:only => :update_post,
:add_flash => { "alert" => "Failed to create your message" },
:redirect_to => :category_url
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言