我有一个关于将数据保存到数据库的问题。这是初学者的问题。我刚开始学习 Ruby on Rails。我的数据库中有一个用户、医生和预约。
class User < ActiveRecord::Base
has_many :appointments
has_many :doctors, :through => :appointments
end
class Doctor < ActiveRecord::Base
has_many :appointments
has_many :users, :through => :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :doctor
belongs_to :user
end
我有以下控制器:
class AppointmentsController < ApplicationController
def create
@appointment = Appointment.new(appointment_params)
if @appointment.save
flash[:success] = "Welcome!"
else
render 'new'
end
end
def destroy
end
end
如何通过 View 将特定约会保存到数据库?如何从视图和设置参数中访问约会控制器中的该方法?
非常感谢你!