【发布时间】:2016-01-20 22:57:29
【问题描述】:
嗨,我创建了这个种子
rails = Course.create(title: "Ruby On Rails")
models = rails.chapters.create(title: "Models")
models.items << Lesson.create(title: "What is Active Record?", content: "Lesson content here")
models.items << Exercice.create(title: "The Active Record pattern", content: "Exo about active record pattern")
models.items << Exercice.create(title: "Object Relational Mapping", content: "Exo about ORM")
models.items << Exercice.create(title: "Active Record as an ORM Framework", content: "Exo about ORM")
models.items << Lesson.create(title: "Convention over Configuration in Active Record", content: "Lesson content here")
models.items << Exercice.create(title: "Naming Conventions", content: "Exo about naming convention")
models.items << Exercice.create(title: "Schema Conventions", content: "Exo about schema convention")
models.items << Lesson.create(title: "Model summary", content: "Lesson content here")
models.items << Exam.create(title: "Rails Models exam", content: "Exam content here")
puts "done"
我已经完成了rake db:seed。
我的控制器课程是:
类 CoursesController 我的控制器章节是: 类章节控制器 我的控制器章节是: 在 app/views/courses/index.html.erb 中 但标题课程多次出现,我只想看一次。如何重置或销毁或隐藏名称相同且结构相同的其他课程? 如果您想了解更多信息,请告诉我我能做什么。谢谢。 def index
@courses = Course.all
end
def show
@course = Course.find(params[:id])
end
end
def show
@course = Course.find(params[:course_id])
@chapter = @course.chapters.find(params[:id])
end
end
class ItemsController < ApplicationController
def show
@course = Course.find(params[:course_id])
@chapter = @course.chapters.find(params[:chapter_id])
@item = @chapter.items.find(params[:id])
end
end
<div class="container-page">
<div class="padding-page">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="page-progress">
<h1>
Page en cours de réalisation
</h1>
<% @courses.each do |course| %>
<h2>
<%= link_to course.title, course %>
</h2>
<% end %>
</div>
</div>
</div>
</div>
</div>
</div>
【问题讨论】:
-
您
Course模型中似乎还有其他记录,请执行Course.all,然后使用输出更新您的问题
标签: ruby-on-rails ruby