Meine Beziehungen sind:keine Daten mithilfe von benutzerdefinierter Aktion zum Einfügen von gehört mit viel Beziehung hat Schienen
class PrivateClass < ActiveRecord::Base
has_many :lesson_plans
end
class LessonPlan < ActiveRecord::Base
belongs_to :private_class
end
Meine Form ist wie:
<%= form_tag (add_lesson_plan_teacher_teacher_private_school_private_class_path), remote: true do %>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<%= label_tag :title, nil, :class => "control-label" %>
<%= text_field_tag "private_class[lesson_plan][title]", "", class: "form-control first_input", required: true, style: "width: 210%;" %>
</div>
<div class="form-group">
<%= label_tag :description, nil, :class => "control-label" %>
<%= text_area_tag "private_class[lesson_plan][description]", "", placeholder: "Enter Description Here", class: "form-control", rows: "3", required: true, style: "width: 210%;" %>
</div>
<div class="form-group">
<%= label_tag :notes, nil, :class => "control-label" %>
<%= text_area_tag "private_class[lesson_plan][notes]", "", placeholder: "Enter Notes Here", class: "form-control", rows: "3", required: true, style: "width: 210%;" %>
</div>
<div class="form-group">
<%= submit_tag "Create lesson plan", :class => "btn btn-info" %>
</div>
</div>
</div>
<% end %>
Mein Controller:
class Teacher::PrivateClassesController < ApplicationController
before_action :authenticate_user!
before_action :set_teacher
before_action :set_private_school
before_action :set_private_class
def add_lesson_plan
@lesson_plan = @private_class.lesson_plans.new(private_class_params).save
end
private
def private_class_params
params.require(:private_class).permit!
end
def set_teacher
@teacher = Teacher.friendly.find(params[:teacher_id])
end
def set_private_school
@private_school = PrivateSchool.friendly.find(params[:private_school_id])
end
def set_private_class
@private_class = PrivateClass.find(params[:id])
end
end
Routen sind:
Jetztdas Problem ist, dass wenn ich versuche, Daten in Lektion einfügen Tabelle plant er sagt:
ActiveRecord::UnknownAttributeError (unknown attribute 'lesson_plan' for LessonPlan.):
app/controllers/teacher/private_classes_controller.rb:11:in `add_lesson_plan'
Was muss ich tun, geben die Unterrichtsplan Felder Daten in Unterrichtsplan Tabelle mit private_class_id Wenn etwas falsch bitte korrigiert mich.
UPDATE
hier sind die Ergebnisse der Anweisung puts:
def add_lesson_plan
puts params.inspect, '++++++++++++++++++++++++'
puts @private_class.lesson_plans.new.inspect, '**************************************'
@lesson_plan = @private_class.lesson_plans.new(private_class_params).save!
end
{"utf8"=>"✓", "private_class"=>{"lesson_plans"=>{"title"=>"ggd", "description"=>"gghh", "notes"=>"gggkd"}}, "commit"=>"Create lesson plan", "controller"=>"teacher/private_classes", "action"=>"add_lesson_plan", "teacher_id"=>"carmel-cynthia", "private_school_id"=>"dr-jasmine-e-mcnair-high-school", "id"=>"1"}
++++++++++++++++++++++++
#<LessonPlan id: nil, title: nil, description: nil, notes: nil, subject_id: nil, teacher_id: nil, created_at: nil, updated_at: nil, is_private: true, is_publish: false, user_id: nil, publish_date: nil, popularity_count: 0, is_special: false, private_class_id: 1>
**************************************
Wenn Sie dont Geist könnten Sie bitte die 'erklären [: lesson_plans]'? Und bitte füge auch die Quelle von ruby doc hinzu. :) Ich meine was genau '[: stunde_plans]' macht? – LearningROR
Ich habe meine Antwort bearbeitet ... Ich hoffe, es hilft;) – gabrielhilal
Vielen Dank. Du hast wirklich meinen Tag gemacht. :) Bleib gesegnet. Ich wünschte, ich könnte dir 10 UPs geben. – LearningROR