Heroku上的ActiveAdmin - 路由无法正常工作

时间:2011-08-28 16:20:55

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

这真令人沮丧。 AA以前对我来说非常好用,我想我几乎尝试了所有东西。这是我的问题:

在localhost上,一切正常,但是一旦我在Heroku,就会发生奇怪的事情。

我的信息中心包含[Badge][Student]等。

我可以通过/admin/badges查看所有徽章。但是,一旦我进行编辑/查看/显示,Heroku就会出错,而在localhost上则可以正常工作。

在检查时,会发生这种情况:

ActionView::Template::Error (No route matches {:action=>"edit", :controller=>"admin/students", :id=>#<Student id: nil, email: "", encrypted_password: "", password_salt: "", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, name: nil, role: nil, school: nil, parent_tutor_email: nil, parent_tutor_token: nil, pending_badge: nil, proficiency: 0.0, created_at: nil, account_type: "free", chargify_id: nil, fb_id: nil, score: 0, level_id: nil, special_bonuses: nil, birthday: nil, edu_level: nil>}):

1: render renderer_for(:show)

:id似乎应该是徽章ID,但它会被Student对象破坏,该对象是空的。

这是我的route.rb文件:

WitsApp::Application.routes.draw do

  ActiveAdmin.routes(self)    
  devise_for :admin_users, ActiveAdmin::Devise.config


  devise_for :students, :controllers => {:registrations => "registrations", :sessions => "students_sessions", :passwords =>"devise/passwords"} do
    match 'students/sign_up'              => 'registrations#create',      :as => "student_sign_up"
    get   'students/sign_out'             => 'students_sessions#destroy'
    get   'students/sign_in'              => 'pages#welcome'
    get   'students/password/new'         => 'devise/passwords#new' 
    get   'students/password/edit'        => 'devise/passwords#edit' 
    post  'students/password'             => 'devise/passwords#create'
    put   'students/password'             => 'devise/passwords#update'

    get   'students', :to => 'students#show', :as => :student_root
    resources :badges
    resources :students
  end

  match '/sign_up' => 'pages#welcome', :as => "sign_up"

  root :to => "pages#home"
end

如果有帮助,这里是rake路线(截断):

admin_dashboard        /admin(.:format)                                       {:action=>"index", :controller=>"admin/dashboard"}
         admin_comments GET    /admin/comments(.:format)                              {:action=>"index", :controller=>"admin/comments"}
                        POST   /admin/comments(.:format)                              {:action=>"create", :controller=>"admin/comments"}
      new_admin_comment GET    /admin/comments/new(.:format)                          {:action=>"new", :controller=>"admin/comments"}
     edit_admin_comment GET    /admin/comments/:id/edit(.:format)                     {:action=>"edit", :controller=>"admin/comments"}
          admin_comment GET    /admin/comments/:id(.:format)                          {:action=>"show", :controller=>"admin/comments"}
                        PUT    /admin/comments/:id(.:format)                          {:action=>"update", :controller=>"admin/comments"}
                        DELETE /admin/comments/:id(.:format)                          {:action=>"destroy", :controller=>"admin/comments"}
           admin_topics GET    /admin/topics(.:format)                                {:action=>"index", :controller=>"admin/topics"}
                        POST   /admin/topics(.:format)                                {:action=>"create", :controller=>"admin/topics"}
        new_admin_topic GET    /admin/topics/new(.:format)                            {:action=>"new", :controller=>"admin/topics"}
       edit_admin_topic GET    /admin/topics/:id/edit(.:format)                       {:action=>"edit", :controller=>"admin/topics"}
            admin_topic GET    /admin/topics/:id(.:format)                            {:action=>"show", :controller=>"admin/topics"}
                        PUT    /admin/topics/:id(.:format)                            {:action=>"update", :controller=>"admin/topics"}
                        DELETE /admin/topics/:id(.:format)                            {:action=>"destroy", :controller=>"admin/topics"}
           admin_badges GET    /admin/badges(.:format)                                {:action=>"index", :controller=>"admin/badges"}
                        POST   /admin/badges(.:format)                                {:action=>"create", :controller=>"admin/badges"}
        new_admin_badge GET    /admin/badges/new(.:format)                            {:action=>"new", :controller=>"admin/badges"}
       edit_admin_badge GET    /admin/badges/:id/edit(.:format)                       {:action=>"edit", :controller=>"admin/badges"}
            admin_badge GET    /admin/badges/:id(.:format)                            {:action=>"show", :controller=>"admin/badges"}
                        PUT    /admin/badges/:id(.:format)                            {:action=>"update", :controller=>"admin/badges"}
                        DELETE /admin/badges/:id(.:format)                            {:action=>"destroy", :controller=>"admin/badges"}
         admin_students GET    /admin/students(.:format)                              {:action=>"index", :controller=>"admin/students"}
                        POST   /admin/students(.:format)                              {:action=>"create", :controller=>"admin/students"}
      new_admin_student GET    /admin/students/new(.:format)                          {:action=>"new", :controller=>"admin/students"}
     edit_admin_student GET    /admin/students/:id/edit(.:format)                     {:action=>"edit", :controller=>"admin/students"}
          admin_student GET    /admin/students/:id(.:format)                          {:action=>"show", :controller=>"admin/students"}
                        PUT    /admin/students/:id(.:format)                          {:action=>"update", :controller=>"admin/students"}
                        DELETE /admin/students/:id(.:format)                          {:action=>"destroy", :controller=>"admin/students"}

有人有什么想法吗?感谢您抽出宝贵时间!

1 个答案:

答案 0 :(得分:0)

经过多次拔毛后,我发现了问题和解决方法。

原因是因为我在def resource中覆盖了ApplicationHelper,并且总是让它返回Student。因此,我必须覆盖def resource,使其看起来像:

def resource
    @resource = Badge.find_by_id(params[:id]) || Badge.new
end

一切都会再次奏效。我不确定为什么它没有提前失败。 :(