2012-05-23 24 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