我不确定发生了什么。我的路线疯了吗?

时间:2012-10-10 00:44:33

标签: ruby-on-rails ruby ruby-on-rails-3

这些是我路线的一部分。

   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

最小视图:

activity_groups /显示

%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

索引有点复杂:

activity_groups /索引

.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消失了。我不能再访问它了。它尝试将我重定向到show视图而不是索引视图。我真的不明白为什么会这样。有什么想法吗?

[EDIT1]

我开始使用干净的数据库。如果我现在尝试为显示页面添加链接,我会收到NameError undefined local variable or method activity_group_path'。

[EDIT2] 更正错误拼写

2 个答案:

答案 0 :(得分:1)

您是否将对象传递到链接路径?

activity_group_path(@activity_group)

答案 1 :(得分:1)

您提到上次使用了activity_groups_path(activity_group) - 这应该是activity_group_path(activity_group)(群组不是群组)。可能是/一个/问题,但也许不是唯一一个。 (也许不是唯一的一个,听起来像你的同一部分的递归调用并将子activity_groups传递为:local可能最终调用带有无效活动组对象的路由。只是预感)

顺便说一句,我在Rails路线上花费了许多类似的挫折时间,这总是归结为我做的一些愚蠢(虽然语法也应该归咎于它,它只是英语的一个不好的近似)。休息一下,吃点东西,小睡一会儿......可能很明显。