OOZOU
ติดต่อเรา
กลับไปหน้า TIL
ruby on rails

ใช้ Pundit Policy จัดการ permitted parameters ทั้งค่า default และแยกราย action

10 กุมภาพันธ์ 2565

ในการจัดการ permitted params คุณสามารถเพิ่ม permitted_attributes และ permitted_attributes_for_#{action} ใน policy ของคุณได้ เช่น

class CommentPolicy < ApplicationPolicy
  def permitted_attributes
    %i[body]
  end

  def permitted_attributes_for_create
    %i[body application_id]
  end
end

จากนั้นใน controller ของคุณ

class CommentController
  def create
    @comment = Comment.create(comment_attributes) # { body: 'body', application_id: 1 }
  end
 
  def update
    @comment = Comment.find(params[:id])
    @comment.update(comment_attributes) # { body: 'new body' }
  end
 
  private def comment_attributes
    permitted_attributes(Comment)
  end
end

เพิ่มเติมเกี่ยวกับ ruby on rails

ruby on rails31 มกราคม 2565

ใช้ `requestSubmit` สำหรับการ submit form ร่วมกับ Turbo

Turbo คอยฟัง event submit ที่เกิดขึ้นบน form ดังนั้นให้ใช้ requestSubmit เสมอเมื่อจะ submit form ด้วย JS

ruby on rails19 มกราคม 2565

ให้ Rubocop และ ESLint ignore gem ที่ bundle ไว้ใน GitHub Actions

โปรเจกต์ Rails มักติดตั้ง gem ลงใน vendor directory ใน GitHub actions เพื่อให้ cache ไว้ใช้ในรอบถัด ๆ ไปได้

ruby on rails18 เมษายน 2564

Rails 6, Ruby 3, Bootstrap 5 และ Hotwire

ต่อยอด blogpost ของ Bootrails ด้วย Hotwire: ของใหม่สุดเท่ทั้งหมด (ณ ตอนที่เขียน TIL นี้):

มีโปรเจกต์ในใจแล้วหรือยัง?

เล่าให้เราฟังเกี่ยวกับโปรเจกต์ใหม่ของคุณ

ติดต่อนัดพูดคุยhello@oozou.com
OOZOU Logo

กรุงเทพฯ · สิงคโปร์ · ฮ่องกง

X
Facebook
Instagram
LinkedIn
OOZOU Co., Ltd.
548 One City Centre
Ploenchit Road
Bangkok 10330
Thailand
+66 2544 0000
hello@oozou.com

บริการ

  • พัฒนาเว็บ
  • AI Agents & Generative AI
  • พัฒนาแอปมือถือ
  • วิศวกรรมและวิเคราะห์ข้อมูล
  • UI/UX และการออกแบบผลิตภัณฑ์
  • Digital Transformation

บริษัท

  • เกี่ยวกับเรา
  • ร่วมงานกับเรา
  • บทความ
  • Case Studies
  • Today I Learned
  • ติดต่อเรา

เพิ่มเติม

  • อุตสาหกรรม
  • เครือข่ายพาร์ทเนอร์
© 2026 OOZOU สงวนลิขสิทธิ์
นโยบายความเป็นส่วนตัวจรรยาบรรณในการทำงานนโยบาย ABAC