在Rails 4上,我正在为我的用户使用设计,我有一个练习脚手架 .

每个用户都有很多练习,每个练习都有很多用户,这是通过一个名为schedule的模型来完成的 .

我想构建一个表单,以便在创建新练习时可以将其分配给用户 . 在创建新练习时,我很少迷失如何允许schedule表同时接受exercise_id和user_id . 任何帮助表示赞赏!

/user.rb

class User < ActiveRecord::Base
    devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

has_many :schedules
has_many :exercises, :through => :schedules

/exercise.rb

class Exercise < ActiveRecord::Base
validates :description, presence: true

has_many :schedules
has_many :users, :through => :schedules

/schedules.rb

class Schedule < ActiveRecord::Base
belongs_to :exercise
belongs_to :user

运动控制器

def exercise_params
  params.require(:exercise).permit(:description, :notes, :video, {:users=>[]})


end

edit

为了让Schedule表填充Exercise_ids和User_ids,我迷失了下一步操作 .

架构:

USERS id电子邮件名称(来自设计的标准列)

EXERCISES id说明created_at updated_at标签说明video_file_name video_content_type video_file_size video_updated_at

SCHEDULE id exercise_id user_id position created_at updated_at