Params没有被传递给Rails 3.0.3中的方法

时间:2011-01-28 17:43:35

标签: ruby ruby-on-rails-3

在我从Rails 2.3.4升级到Rails 3.0.3之后,我又遇到了一个非常令人费解的问题。

我使用以下网址调用'show'控制器方法:

/节/ 10

我在终端

中看到了这一点
  

开始为127.0.0.1获取“/ verse / 10”   在2011-01-27 16:17:58 -0800

     

VersesController处理#show   作为HTML
   * 搜索ID为

的诗句      

在其中呈现经文/ show.html.erb   布局/应用(76.6ms)

     

在1006毫秒内完成200 OK(浏览次数:   125.4ms | ActiveRecord:9.8ms)

这节经文的方法非常简单:

  def show
    logger.debug("*** Searching for verse with ID: #{params[:id]}")
    @vs = Verse.find(params[:id])
  end

路线定义如下:

match '/verse/:id', :to => 'verses#show', :as => 'verse'

问题:参数ID,在这种情况下是'10',没有被传递到控制器方法,因此抛出了404,因为params [:id]是nil。

“rake routes | grep verse”的输出如下:

  

verse /verse/:id(.:format){:controller =>“verses”,:action =>“show”}

我已经花了很多年的时间,但觉得我错过了一些非常明显的东西。


以下是完整的佣金路线输出:

                   login        /login(.:format)                                  {:controller=>"sessions", :action=>"new"}
                  logout        /logout(.:format)                                 {:controller=>"sessions", :action=>"destroy"}
                register        /register(.:format)                               {:controller=>"users", :action=>"create"}
                  signup        /signup(.:format)                                 {:controller=>"users", :action=>"new"}
                activate        /activate/:activation_code(.:format)              {:activation_code=>nil, :controller=>"users", :action=>"activate"}
         forgot_password        /forgot_password(.:format)                        {:controller=>"passwords", :action=>"new"}
         change_password        /change_password/:reset_code(.:format)            {:controller=>"passwords", :action=>"reset"}
        open_id_complete GET    /opensession(.:format)                            {:controller=>"sessions", :action=>"create"}
          open_id_create GET    /opencreate(.:format)                             {:controller=>"users", :action=>"create"}
                   users GET    /users(.:format)                                  {:action=>"index", :controller=>"users"}
                         POST   /users(.:format)                                  {:action=>"create", :controller=>"users"}
                new_user GET    /users/new(.:format)                              {:action=>"new", :controller=>"users"}
               edit_user GET    /users/:id/edit(.:format)                         {:action=>"edit", :controller=>"users"}
                    user GET    /users/:id(.:format)                              {:action=>"show", :controller=>"users"}
                         PUT    /users/:id(.:format)                              {:action=>"update", :controller=>"users"}
                         DELETE /users/:id(.:format)                              {:action=>"destroy", :controller=>"users"}
               passwords GET    /passwords(.:format)                              {:action=>"index", :controller=>"passwords"}
                         POST   /passwords(.:format)                              {:action=>"create", :controller=>"passwords"}
            new_password GET    /passwords/new(.:format)                          {:action=>"new", :controller=>"passwords"}
           edit_password GET    /passwords/:id/edit(.:format)                     {:action=>"edit", :controller=>"passwords"}
                password GET    /passwords/:id(.:format)                          {:action=>"show", :controller=>"passwords"}
                         PUT    /passwords/:id(.:format)                          {:action=>"update", :controller=>"passwords"}
                         DELETE /passwords/:id(.:format)                          {:action=>"destroy", :controller=>"passwords"}
                 session POST   /session(.:format)                                {:action=>"create", :controller=>"sessions"}
             new_session GET    /session/new(.:format)                            {:action=>"new", :controller=>"sessions"}
            edit_session GET    /session/edit(.:format)                           {:action=>"edit", :controller=>"sessions"}
                         GET    /session(.:format)                                {:action=>"show", :controller=>"sessions"}
                         PUT    /session(.:format)                                {:action=>"update", :controller=>"sessions"}
                         DELETE /session(.:format)                                {:action=>"destroy", :controller=>"sessions"}
                  quests GET    /quests(.:format)                                 {:action=>"index", :controller=>"quests"}
                         POST   /quests(.:format)                                 {:action=>"create", :controller=>"quests"}
               new_quest GET    /quests/new(.:format)                             {:action=>"new", :controller=>"quests"}
              edit_quest GET    /quests/:id/edit(.:format)                        {:action=>"edit", :controller=>"quests"}
                   quest GET    /quests/:id(.:format)                             {:action=>"show", :controller=>"quests"}
                         PUT    /quests/:id(.:format)                             {:action=>"update", :controller=>"quests"}
                         DELETE /quests/:id(.:format)                             {:action=>"destroy", :controller=>"quests"}
                   index        /home(.:format)                                   {:controller=>"verses", :action=>"index"}
            starter_pack        /starter_pack(.:format)                           {:controller=>"verses", :action=>"starter_pack"}
                   *verse        /verse/:id(.:format)                                 {:controller=>"verses", :action=>"show"}*
               tag_cloud        /tag_cloud(.:format)                              {:controller=>"verses", :action=>"tag_cloud"}
          show_user_info        /show_user_info(.:format)                         {:controller=>"admin", :action=>"show_user_info"}
               show_tags        /show_tags(.:format)                              {:controller=>"admin", :action=>"show_tags"}
                 contact        /contact(.:format)                                {:controller=>"info", :action=>"contact"}
                     faq        /faq(.:format)                                    {:controller=>"info", :action=>"faq"}
                tutorial        /tutorial(.:format)                               {:controller=>"info", :action=>"tutorial"}
               volunteer        /volunteer(.:format)                              {:controller=>"info", :action=>"volunteer"}
             leaderboard        /leaderboard(.:format)                            {:controller=>"info", :action=>"leaderboard"}
              stateboard        /stateboard(.:format)                             {:controller=>"info", :action=>"stateboard"}
            countryboard        /countryboard(.:format)                           {:controller=>"info", :action=>"countryboard"}
           referralboard        /referralboard(.:format)                          {:controller=>"info", :action=>"referralboard"}
                    news        /news(.:format)                                   {:controller=>"info", :action=>"news"}
          update_profile        /update_profile(.:format)                         {:controller=>"profile", :action=>"update_profile"}
               referrals        /referrals/:id(.:format)                          {:controller=>"profile", :action=>"referrals"}
             unsubscribe        /unsubscribe/*email(.:format)                     {:controller=>"profile", :action=>"unsubscribe"}
                edit_tag        /edit_tag/:id(.:format)                           {:controller=>"tag", :action=>"edit_tag"}
                  tweets        /tweets(.:format)                                 {:controller=>"tweets", :action=>"index"}
           load_progress        /load_progress/:user(.:format)                    {:controller=>"chart", :action=>"load_progress"}
                    root        /(.:format)                                       {:controller=>"sessions", :action=>"new"}
                    home        /home(.:format)                                   {:controller=>"sessions", :action=>"new"}
                                /:controller(/:action(/:id))(.:format)  

1 个答案:

答案 0 :(得分:1)

如果您安装了open_id_authentication插件,则可能会干扰您的路线。