0

我无法弄清楚如何使我的 Rails 应用程序与中央仪表板一起工作。基本上我希望它能够工作,以便当用户从列表中单击课程时,课程的详细信息会加载到仪表板中。ajax 部分并不太复杂,但是当不使用 ajax 时,我在加载部分时有点挣扎。我想我可以简单地在视图中放置一些逻辑,这样如果 @course != null 它将加载部分。

这些路线也给我带来了一些困难。所以我希望网址类似于以下内容:dashboard/student/:id/university/:id/course/:id

我想出了以下方法,但有更好的方法吗? http://pastebin.com/keEmaznw

4

1 回答 1

0

It's hard to understand your question. You've given us scant detail, and insufficient code. That said, regarding loading a partial with a nil object:

If you pass an object to a partial, Rails will take care of the rendering for you automatically, and no nil (instead of null, in Ruby talk) check is necessary:

= render @object

Regarding routes, yes, there is a better way: You should generally avoid nesting your routes more than two levels. This becomes a nightmare to test, and you end up writing very long method names:

edit_dashboard_student_university_course_path(@university, @course, @student)

You really don't want to be writing that in your view or your tests. think about it, if you want to edit a student, is it necessary to load the university and the course as well?

于 2013-06-25T14:05:56.273 回答