Rails路由问题 - 未初始化的常量游戏

时间:2012-03-25 02:39:42

标签: ruby-on-rails routes uninitialized-constant

我的rails路由文件有问题。我的路线文件中有以下匹配项:

  match '/games/:game_id/increment_cool' => 'games/:game_id#increment_cool', :as => 'games_incrementcool'

然后我尝试在我的游戏视图中使用此路线,如下所示:

<%= link_to 'Cool!', games_incrementcool_path(@game) %>

但是我收到了路由错误uninitialized constant Games

rake路线显示:

(in /home/sumdeos/RIT48/oneCoolGameADay)
                          profile_index GET    /profile/index(.:format)
                       new_user_session GET    /users/sign_in(.:format)
                           user_session POST   /users/sign_in(.:format)
                   destroy_user_session DELETE /users/sign_out(.:format)
                 user_omniauth_callback        /users/auth/:action/callback(.r)
                          user_password POST   /users/password(.:format)
                      new_user_password GET    /users/password/new(.:format)
                     edit_user_password GET    /users/password/edit(.:format)
                                        PUT    /users/password(.:format)
               cancel_user_registration GET    /users/cancel(.:format)
                      user_registration POST   /users(.:format)
                  new_user_registration GET    /users/sign_up(.:format)
                 edit_user_registration GET    /users/edit(.:format)
                                        PUT    /users(.:format)
                                        DELETE /users(.:format)
submitLeaderboardStatistic_game_leaderboard POST   /games/:game_id/leaderboards/:
                      game_leaderboards GET    /games/:game_id/leaderboards(.
                                        POST   /games/:game_id/leaderboards(.
                   new_game_leaderboard GET    /games/:game_id/leaderboards/n
                  edit_game_leaderboard GET    /games/:game_id/leaderboards/:
                       game_leaderboard GET    /games/:game_id/leaderboards/:
                                        PUT    /games/:game_id/leaderboards/:
                                        DELETE /games/:game_id/leaderboards/:
                                  games GET    /games(.:format)
                                        POST   /games(.:format)
                               new_game GET    /games/new(.:format)
                              edit_game GET    /games/:id/edit(.:format)
                                   game GET    /games/:id(.:format)
                                        PUT    /games/:id(.:format)
                                        DELETE /games/:id(.:format)
                    games_incrementcool        /game/:game_id/increment_cool(
                             home_index GET    /home/index(.:format)
                                   root        /

我已经尝试了许多不同的方法来完成这项工作,但它们都没有奏效。

如何让我的视图在我的游戏控制器中调用increment_cool方法?提前谢谢!

1 个答案:

答案 0 :(得分:0)

这就是匹配的方式:match '/posts' => 'posts#index'

第一个字符串是路由,第二个字符串是由#。

分隔的控制器/操作组合

'games#increment_cool'代表increment_cool控制器的games操作。

match '/games/:game_id/increment_cool' => 'games#increment_cool', :as => 'games_incrementcool'

虽然您应该在:as选项中使用单数“游戏”出于语义原因,因为它正在处理单一资源。可能类似于game_increment_coolincrement_cool_game