2012-07-20 78 views
0

导致的routes.rb:导轨3:自定义路线在 '未定义局部变量或方法'

resources :conversations, only: [:index, :show, :new, :create, :destroy] do 
    collection do 
    get :inbox 
    end 

在我的控制器:

def inbox 
    <stuff> 
end 

我认为(使用HAML):

=link_to 'Inbox', inbox_conversations, :id => 'load-inbox', :class => 'message-control-highlight', :remote => true 

我得到的页面加载以下错误:

undefined local variable or method `inbox_conversations' for #<#<Class:0x3d51470>:0x3d59198> 

在我看来,如果我用“#”取代inbox_conversations,我不会在页面加载时出现任何错误。我试着用可能的类来追加inbox_conversation,比如current_user和current_user.mailbox。我也试着改变从集合到成员的路由 - 甚至将它从任何集合/成员块中取出。这里可能是什么问题?

回答

1

尝试使用inbox_conversations_pathinbox_conversations_url

=link_to 'Inbox', inbox_conversations_path, :id => 'load-inbox', :class => 'message-control-highlight', :remote => true

1

您需要添加_path_url你的路线,例如

= link_to 'Inbox', inbox_conversations_path 

参见所有细节的完整的Rails路由指南:

http://guides.rubyonrails.org/routing.html

+0

谢谢两位。那只是我需要的答案。 – nullnullnull 2012-07-20 19:04:05

相关问题