рельсы: создание моделей - PullRequest
1 голос
/ 01 февраля 2012

Привет, у меня есть модель, которая выглядит так:

The id of class and teacher is 1 to 1.
Class has_many grades
Grade belongs_to class

Это мой контроллер домашней страницы:

  @grade = Grade.new
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @grade }
  end

Это мой диспетчер классов:

  def create
    class = Class.find(current_teacher.id)
    ****@grade = class.grades.build(params[:grade])

    respond_to do |format|
      if @grade.save
        format.html { redirect_to @grade, notice: 'Grade was successfully created.' }
        format.json { render json: @grade, status: :created, location: @grade }
      else
        format.html { render action: "new" }
        format.json { render json: @grade.errors, status: :unprocessable_entity }
      end
    end
  end

В настоящее время я получаю эту ошибку в строке с **

unknown attribute: class_id

Как это исправить?

Другой вопрос, у меня тоже есть

grade belongs_to student
student belongs_to grade

Как добавить это также в метод create / new?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...