optimism: use model.erorrs.any? instead of model.invalid?

https://github.com/leastbad/optimism/blob/master/lib/optimism.rb#L73

before

  Post Exists? (0.2ms)  SELECT 1 AS one FROM "posts" WHERE "posts"."name" = ? AND "posts"."id" != ? LIMIT ?  [["name", "222"], ["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/posts_controller.rb:59:in `block (2 levels) in update'
  CACHE Post Exists? (0.0ms)  SELECT 1 AS one FROM "posts" WHERE "posts"."name" = ? AND "posts"."id" != ? LIMIT ?  [["name", "222"], ["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/posts_controller.rb:59:in `block (2 levels) in update'
  CACHE Post Exists? (0.0ms)  SELECT 1 AS one FROM "posts" WHERE "posts"."name" = ? AND "posts"."id" != ? LIMIT ?  [["name", "222"], ["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/posts_controller.rb:59:in `block (2 levels) in update'
  CACHE Post Exists? (0.0ms)  SELECT 1 AS one FROM "posts" WHERE "posts"."name" = ? AND "posts"."id" != ? LIMIT ?  [["name", "222"], ["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/posts_controller.rb:59:in `block (2 levels) in update'
  CACHE Post Exists? (0.0ms)  SELECT 1 AS one FROM "posts" WHERE "posts"."name" = ? AND "posts"."id" != ? LIMIT ?  [["name", "222"], ["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/posts_controller.rb:59:in `block (2 levels) in update'
[ActionCable] Broadcasting to OptimismChannel: {"cableReady"=>true, "operations"=>{"addCssClass"=>[{"selector"=>"#post_age_container", "name"=>"error"}, {"selector"=>"#post_form", "name"=>"invalid"}], "removeCssClass"=>[{"selector"=>"#post_name_container", "name"=>"error"}, {"selector"=>"#post_body_container", "name"=>"error"}, {"selector"=>"#post_consent_container", "name"=>"error"}], "textContent"=>[{"selector"=>"#post_name_error", "text"=>""}, {"selector"=>"#post_age_error", "text"=>"Age must be greater than or equal to 18"}, {"selector"=>"#post_body_error", "text"=>""}, {"selector"=>"#post_consent_error", "text"=>""}]}}

after

  Post Exists? (0.2ms)  SELECT 1 AS one FROM "posts" WHERE "posts"."name" = ? AND "posts"."id" != ? LIMIT ?  [["name", "222"], ["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/posts_controller.rb:59:in `block (2 levels) in update'
[ActionCable] Broadcasting to OptimismChannel: {"cableReady"=>true, "operations"=>{"addCssClass"=>[{"selector"=>"#post_age_container", "name"=>"error"}, {"selector"=>"#post_form", "name"=>"invalid"}], "removeCssClass"=>[{"selector"=>"#post_name_container", "name"=>"error"}, {"selector"=>"#post_body_container", "name"=>"error"}, {"selector"=>"#post_consent_container", "name"=>"error"}], "textContent"=>[{"selector"=>"#post_name_error", "text"=>""}, {"selector"=>"#post_age_error", "text"=>"Age must be greater than or equal to 18"}, {"selector"=>"#post_body_error", "text"=>""}, {"selector"=>"#post_consent_error", "text"=>""}]}}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (11 by maintainers)

Most upvoted comments

@leastbad Thanks, that works.