开发者

ActiveAdmin on Heroku - routes not working properly

This is really frustrating. AA used to work very well for me, and I think I've tried almost everything. Here's my problem:

On localhost, everything works fine, but once I'm in Heroku, weird things happen.

My Dashboard has [Badge] and [Student], among others.

I c开发者_运维技巧an view all the badges via /admin/badges. However, once I do an Edit/View/Show, things go wrong on Heroku, whereas it works fine on localhost.

On inspection, this happens:

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)

It seems that :id is supposed to be the Badge id, but it gets clobbered up by the Student object, which is empty.

Here's my route.rb file:

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

Here's rake routes (truncated) if it helps:

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"}

Anyone have any ideas? Thank you for taking the time!


After much hair pulling, I've found the problem and solution.

The reason is because I have overridden def resource in the ApplicationHelper, and always make it return a Student. Therefore, I had to override def resource such that it looks like:

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

And everything would work again. I'm just not sure why it didn't fail earlier. :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜