1

我正在尝试使用 Rails 4.0、slim、simple_form gem 和改革 gem 为我的 web 应用程序构建一个服务表单。

services 表“属于”city、vehicle_type、driver 和 customer 表。

服务模式:

class Service < ActiveRecord::Base
  has_paper_trail

  # Constants
  ACCEPTED_BRANCH_OFFICES = [ 'diadema', 'valinhos' ]
  ACCEPTED_SERVICE_TYPES = [ 'retail', 'contract' ]
  ACCEPTED_PRICING_TYPES = [ 'fixed', 'not_fixed' ]
  ACCEPTED_MANAGEMENT_STATUSES = [ "waiting_confirmation", 'confirmed', 'canceled']      
  ACCEPTED_PAYMENT_METHODS = [ 'contract', 'billet_banking' ]

  # relations
  belongs_to :customer
  belongs_to :one_way_travel_driver, class_name: 'Driver'
  belongs_to :return_trip_driver, class_name: 'Driver'
  belongs_to :origin_city, class_name: 'City'
  belongs_to :destiny_city, class_name: 'City'
  belongs_to :vehicle_type
  has_one :configuration_table

  # validations
  validates :origin_city, presence: true
  validates :destiny_city, presence: true
  validates :customer_id, presence: true
  validates :one_way_travel_driver, presence: true
  validates :return_trip_driver, presence: true
  validates :vehicle_type_id, presence: true  
  [...]
end

以及部分服务形式:

= f.input :origin_city_id, collection: City.order(:name)
= f.input :destiny_city_id, collection: City.order(:name)
= f.input :one_way_travel_driver_id, collection: Driver.order(:name)
= f.input :return_trip_driver_id, collection: Driver.order(:name)

我想获取表单的 origin_city_id、fatday_city_id、one_way_travel_driver_id 和 return_trip_driver_id(来自 City 和 Driver 表)。

如何使用改革 gem 和表单对象来做到这一点?我需要使用合成吗?

4

0 回答 0