Ich habe zwei Modelle, Project und Todo.Laden von Daten von Fixtures in die Datenbank (Assoziationen)
Projekt speichert eine Reihe von Todos.
Migration für Projekt:
def up
create_table :projects do |t|
t.string :title, null: false
t.timestamps null: false
end
end
Migration für Todo:
def up
create_table :todos do |t|
t.string :text, null: false
t.boolean :isCompleted, null:false
t.integer :project_id, null:false
t.timestamps null: false
end
end
project.rb
class Project < ActiveRecord::Base
has_many :todos
end
todo.rb
class Todo < ActiveRecord::Base
belongs_to :project
end
projects.yml
family:
title: 'Семья'
work:
title: 'Работа'
therest:
title: 'Прочее'
todos.yml
family_todos:
text: 'Купить молоко'
isCompleted: false
project_id: family
work_todos:
text: 'Закончить проект'
isCompleted: false
project_id: work
therest_todos:
text: 'Познать бесконечность'
isCompleted: true
project_id: therest
Wie kann ich sie richtig zu verbinden, so dass, wenn ich ein Projekt nennen kann ich alle todos darin sehen? Außerdem bin ich gespannt wie ich das Datum über die Yml-Dateien wie ein Array hinzufügen kann?
Können Sie mir antworten - ich, wie ich bekommen kann alle Todos? Zum Beispiel muss ich alle Todos aus meinem Familienprojekt drucken. <% = project.todos. . .%> – NanoBreaker
Sie können <% = Project.where (title: "family"). Todos%> –