مرجع سريع

ورقة غش SimpleForm

دليل مرجعي سريع لحزمة SimpleForm في Ruby on Rails: مساعدات الإدخال، أغلفة النماذج وخيارات الحقول.

· تاريخ النشر

توفر SimpleForm دوال مساعدة مرنة لنماذج تطبيقات Ruby on Rails.

قالب النموذج الأساسي

<%= simple_form_for @user do |f| %>
  <%= f.input :email, required: true, autofocus: true %>
  <%= f.input :password, required: true %>
  <%= f.input :remember_me, as: :boolean %>
  <%= f.button :submit, "Sign in", class: "btn-primary" %>
<% end %>

أنواع المدخلات وخياراتها

<%= f.input :bio, as: :text, input_html: { rows: 5 } %>
<%= f.input :role, collection: ['Admin', 'Editor', 'Subscriber'], prompt: "Select Role" %>
<%= f.input :birth_date, as: :date, start_year: 1980 %>
<%= f.input :accepted_terms, as: :boolean, label: "I accept the terms and conditions" %>

أغلفة النماذج المخصصة (Wrappers)

<%# تطبيق غلاف مخصص تم تعريفه في config/initializers/simple_form.rb %>
<%= simple_form_for @user, wrapper: :inline_form do |f| %>
  <%= f.input :query, label: false, placeholder: "Search..." %>
  <%= f.button :submit, "Search" %>
<% end %>

علاقات النماذج (Form Associations)

<%# علاقات Belongs to و Has many %>
<%= f.association :company, collection: Company.all, prompt: "Choose Company" %>
<%= f.association :roles, as: :check_boxes %>

موضوعات ذات صلة