# ฟอร์ม Rails (Ruby on Rails) > form_with, model forms, form_for legacy, strong parameters, nested attributes, file uploads - 20 คำถามสัมภาษณ์ - Mid-Level - [คำถามสัมภาษณ์: Ruby on Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions.md) ## 1. form helper ใดที่แนะนำใน Rails 5.1+ สำหรับการสร้างฟอร์ม? **คำตอบ** form_with คือ helper แบบรวมที่เปิดตัวใน Rails 5.1 ซึ่งแทนที่ form_for และ form_tag โดยค่าเริ่มต้นจะสร้างฟอร์มด้วย remote: true (คำขอ AJAX) และทำให้ไวยากรณ์ง่ายขึ้นด้วยการตรวจจับอัตโนมัติว่ามีการส่งอ็อบเจกต์โมเดลเข้ามาหรือไม่ การรวมนี้ลดความสับสนระหว่าง helper เก่าทั้งสองตัวและให้ API ที่สอดคล้องกันมากขึ้น ## 2. ความแตกต่างระหว่าง form_with model: @user และ form_with url: users_path คืออะไร? **คำตอบ** เมื่อใช้ model: @user, Rails จะกำหนด URL และเมธอด HTTP โดยอัตโนมัติตามสถานะของอ็อบเจกต์ (new_record? หรือ persisted?) สำหรับเรคคอร์ดใหม่จะใช้ POST ไปยัง users_path สำหรับเรคคอร์ดที่มีอยู่แล้วจะใช้ PATCH ไปยัง user_path(@user) ส่วน url: users_path ต้องระบุ URL และเมธอด HTTP ที่เหมาะสมด้วยตนเอง ## 3. จะปิดการส่งแบบ AJAX ที่เป็นค่าเริ่มต้นของ form_with เพื่อให้ได้การส่งแบบ HTML คลาสสิกได้อย่างไร? **คำตอบ** โดยค่าเริ่มต้น form_with จะสร้างฟอร์มที่มี data-remote='true' ซึ่งส่งคำขอ AJAX หากต้องการการส่งแบบ HTML ดั้งเดิมพร้อมการโหลดหน้าใหม่ ต้องเพิ่ม local: true ตั้งแต่ Rails 6.1 เป็นต้นไป สามารถกำหนดพฤติกรรมเริ่มต้นแบบทั่วทั้งระบบผ่าน config.action_view.form_with_generates_remote_forms ## มีอีก 17 คำถาม - บทบาทของ strong parameters ในบริบทของฟอร์ม Rails คืออะไร? - จะกำหนดเมธอด strong parameters สำหรับโมเดล Article ที่มี title และ content อย่างถูกต้องได้อย่างไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Ruby on Rails อื่นๆ - [พื้นฐาน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-basics.md): 25 คำถาม, Junior - [การเขียนโปรแกรมเชิงวัตถุใน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-oop.md): 20 คำถาม, Junior - [พื้นฐาน Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-fundamentals.md): 18 คำถาม, Junior - [Routing & Controllers](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/routing-controllers.md): 22 คำถาม, Junior - [พื้นฐาน ActiveRecord](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-basics.md): 25 คำถาม, Junior - [Views และ ERB Templates](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/views-erb-templates.md): 20 คำถาม, Junior - [การเชื่อมโยงของ ActiveRecord](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-associations.md): 24 คำถาม, Mid-Level - [การสอบถาม ActiveRecord ขั้นสูง](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-record-queries.md): 28 คำถาม, Mid-Level - [การยืนยันตัวตนและการอนุญาต](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/authentication-authorization.md): 22 คำถาม, Mid-Level - [Asset Pipeline สมัยใหม่และ frontend](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-asset-pipeline.md): 18 คำถาม, Mid-Level - [โหมด API ของ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-api-mode.md): 20 คำถาม, Mid-Level - [การทดสอบด้วย RSpec](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-testing-rspec.md): 24 คำถาม, Mid-Level - [ActiveJob & Background Jobs](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-job-background-jobs.md): 20 คำถาม, Mid-Level - [ActionCable & WebSockets](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/action-cable-websockets.md): 18 คำถาม, Mid-Level - [ActionMailer](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/action-mailer.md): 18 คำถาม, Mid-Level - [ActiveStorage](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/active-storage.md): 20 คำถาม, Mid-Level - [กลยุทธ์การ Caching](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/caching-strategies.md): 20 คำถาม, Mid-Level - [การ Migration ขั้นสูง](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/database-migrations-advanced.md): 20 คำถาม, Mid-Level - [Rails Engines และแอปแบบโมดูลาร์](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-engines-modular-apps.md): 18 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/performance-optimization.md): 26 คำถาม, Senior - [Design Patterns ใน Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-design-patterns.md): 22 คำถาม, Senior - [เมตาโปรแกรมมิงใน Ruby](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/ruby-metaprogramming.md): 20 คำถาม, Senior - [ความปลอดภัยของ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-security.md): 22 คำถาม, Senior - [GraphQL กับ Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/graphql-rails.md): 20 คำถาม, Senior - [การดีพลอยและโปรดักชัน](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-deployment-production.md): 20 คำถาม, Senior - [Monitoring & Logging](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/monitoring-logging.md): 20 คำถาม, Senior - [กลยุทธ์การอัปเกรด Rails](https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-upgrade-strategies.md): 18 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/ruby-on-rails/interview-questions/rails-forms