2012-05-23 31 views
0

環境:的link_to失敗,並在同一頁上其他的link_to的,但單獨工作

  • 的Rails 3.2.3
  • 的Mac OS X Lion的
  • 的Ruby-1.9.3-P194(MRI)

我有一個rails應用程序,我使用app/views/layouts/application.html.erb作爲一種'left-nav-pane'作爲我用作菜單選項的一些鏈接。

在菜單中有兩個使用link_to的鏈接(這裏簡寫爲簡化)。如果我刪除一個鏈接並運行該應用程序,則剩餘的鏈接將執行它應該執行的操作。如果我刪除第二個鏈接並恢復第一個鏈接,那麼第一個鏈接將執行IT應該執行的操作。

但是,如果我同時在菜單中同時有兩個鏈接,請單擊其中一個鏈接,但單擊第二個鏈接會創建運行時錯誤。

使用Pry和Rails源代碼本身(3.2.3),我已經指出了框架中發生錯誤的位置。該異常發生在ActionPack的-3.2.3/LIB/ACTION_VIEW/template.rb和渲染方法是發生在下面的代碼行:

def render(view, locals, buffer=nil, &block) 
    ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do 
    compile!(view) 
    view.send(method_name, locals, buffer, &block) # <----ERROR OCCURS HERE 
    end 
rescue Exception => e 
    handle_render_error(view, e) 
end 

METHOD_NAME的值= _app_views_layouts_application_html_erb___1387085669206687706_70334317584180

在視圖上是通過這個名字的方法是。當執行「發送」時,會產生以下異常。

ActionController::RoutingError: No route matches {:action=>"signup_for_role",  
:controller=>"assignments", :club_id=>nil, :member_id=>[#<Member id: 2, first_name: 
"Joseph", last_name: "Smith", start_date: "2012-01-01", end_date: "9999-12-31", 
created_at: "2012-04-07 13:58:46", updated_at: "2012-05-06 21:54:12", club_id: 2, email:  
"[email protected]", assignable: true, address_one: nil, address_two: nil, city: nil, 
state: nil, zip_code: nil, phone: nil, mobile_phone: nil>]} 

由於該方法中的代碼是由導軌,而不是在源代碼文件中生成,我無法通過它與撬到步驟;我只能'發送'消息並查看結果。

下面是從佈局問題的兩個環節代碼:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>MyApp</title> 
    <%= stylesheet_link_tag "application" %> 
    <%= javascript_include_tag "application" %> 
    <%= csrf_meta_tags %> 
    </head> 
    <body> 
    <div style='padding-left:10px; margin-top:10px; ' > 
     <div class='container' style='margin-top:50px; margin-left:50px;padding-right:200px; '> 

     <!-- This link_to works, whether alone, or when the other link_to is present --> 
     <%= link_to "Sign Up for a Role", signup_for_role_club_member_assignments_path(params[:club_id], current_user_as_member) %> 
     <br/><br/> 

     <!-- This link_to fails when both link_to's are present, but works when the other link_to is removed. --> 
     <%= link_to "Clubs", clubs_path %><br> 


     </div> 
     <!-- ***************************************************************** --> 
     <!-- Yield below... this is where the currently selected view displays --> 
     <!-- ***************************************************************** --> 
     <div class='container' style='margin-left:200px' > 
     <%= yield %> 
     </div> 
    </div> 
    </body> 
</html> 

最後,這裏是我的routes.rb文件:

Rolemaster::Application.routes.draw do 

    resources :sessions 
    resources :enrollments 
    resources :logs 

    resources :clubs do 
    resources :members do 
     resources :assignments do 
     collection do 
      get 'signup_for_role' 
      get 'display_success' 
      get 'past_activity' 
     end 
     end 
     resources :absences 
    end 
    resources :roles 
    resources :role_groups 

    resources :meetings do 
     get 'forassignment', :on => :collection 
     get 'print' 
     resources :assignments 
    end 

    resources :assignments do 
     post 'generate', :on => :collection 
    end 
    resources :absences do 
     get 'list', :on => :collection 
    end 
    end 


    resources :users do 
    put "update_password" => "users#update_password" 
    put "update_email" => "users#update_email" 
    get "edit_password" => "users#edit_password" 
    get "edit_email" => "users#edit_email" 
    end 

    match "agendas/print" 
    get "enrollments/new" 
    post "enrollments/create" 
    get "log_in" => "sessions#new", :as => "log_in" 
    get "log_out" => "sessions#destroy", :as => "log_out" 
    get "sign_up" => 'users#new', :as => 'sign_up' 
    get "test/email" 
    get "sessions/revoke_admin" 
    get "sessions/revoke_super_user" 


    get "admins" => "admins#index" 
    root :to => 'sessions#new' 
end 

任何幫助是極大的讚賞。到目前爲止,我可能花了20個小時甚至更多。

+0

但你有錯誤與第一鏈接... club_id零和member_id是陣列 –

+0

尤里...第一個鏈接的作品尋找和設計。 current_user_as_member是我的ApplicationController中的一個方法,它返回登錄用戶的正確值。 因此,該鏈接的作品找到。這是(應該)超級簡單的俱樂部不起作用。 – MotownJoe

+0

另外,我應該提到,這兩個鏈路的ROUTING確實有效。他們在正確的控制器中獲得正確的操作。這是發生問題的視圖渲染。 – MotownJoe

回答

0

務必閱讀錯誤消息,真相就在那裏)

params[:club_id] is nil