这些是我路线的一部分。
activity_groups GET /activity_groups(.:format) activity_groups#index
POST /activity_groups(.:format) activity_groups#create
new_activity_group GET /activity_groups/new(.:format) activity_groups#new
edit_activity_group GET /activity_groups/:id/edit(.:format) activity_groups#edit
activity_group GET /activity_groups/:id(.:format) activity_groups#show
PUT /activity_groups/:id(.:format) activity_groups#update
DELETE /activity_groups/:id(.:format) activity_groups#destroy
root / main#index
最小视图:
活动组/显示
%h2 Activity Ggroup
%h3= @activity_group.title
= link_to "Edit", edit_activity_group_path(@activity_group)
|
= link_to "Delete", activity_group_path(@activity_group), {confirm: (I18n.t "confirmations.activity_group.delete"), method: :delete}
|
= link_to "Back", activity_groups_path
索引有点复杂:
活动组/索引
.row
.span8
%h1.padding_bottom1 Activity Groups
- if !@activity_groups.empty?
%ul.span6
%li.span1 F
%li.span2 Name
%li.span2 Actions
= render @activity_groups
= render @activities
- else
%h2.extra_padding You have no Activity Groups yet. Add one and start managing your time.
.span6.padding_top1
=link_to "Create Activity Group", new_activity_group_path, {class: 'btn'}
=link_to "Create Activity", new_activity_path, {class: 'btn'}
activity_groups/_activity_group.html.haml
%ul.span6
%li.span1
%i.icon-folder-close.folder
%li.span2
= activity_group.title
%li.span2
PROBLEM
- if !activity_group.activity_groups.empty?
- activity_group.activity_groups.each do |activity_group|
= render partial: 'activity_group', locals: {activity_group: activity_group}
- if !activity_group.activities.empty?
- activity_group.activities.each do |activity|
= render partial: 'activities/activity', locals: {activity: activity}
问题如果我放在link_to "Show", activity_groups_path(activity_group)
这里,我的路线会发疯。我的 activity_groups_path 不见了。我不能再访问它了。它试图将我重定向到显示视图而不是索引视图。我真的不明白为什么会这样。有任何想法吗?
[编辑1]
我从一个干净的数据库开始。如果我现在尝试为显示页面放置一个链接,我会得到一个 NameError undefined local variable or method
activity_group_path'`
[EDIT2]更正了上面的拼写错误