2011-08-25 54 views
0

我在我的路線定義的資源文件,如下所示:的Rails 3.0成員路由問題

resources :accounts, :only => [:show, :new, :edit, :create, :update], :member => { 
:profile_avatar => :get 
} 

反過來,我的賬戶#顯示視圖我有以下代碼:

<%= image_tag(profile_avatar_account_path(@account, :jpg), :alt => "#{@account.username}", :title => "#{@account.username}") %> 

當拉起頁面我在我的生產日誌中出現以下錯誤:

ActionView::Template::Error (undefined method `profile_avatar_account_path' for #<#<Class:0x7f3fdb166260>:0x7f3fdb7bc4e8>): 

是否rails 3.0不再支持成員或者是否存在差異這樣做的不同方式?

謝謝

布賴恩

回答

2

應該

resources :accounts, :only => [:show, :new, :edit, :create, :update] do 
    member do 
    get 'profile_avatar' 
    end 

    # or 

    get 'profile_avatar', :on => :member 
end 
+0

這是一個很好的綜合,+1 :) – apneadiving

+0

太棒了!這工作。謝謝。 – Brian

1

嘗試:

resources :accounts, :only => [:show, :new, :edit, :create, :update] do 
    get => 'profile_avatar', :on => :member 
end 
+0

補充說,我的路線的乘客無法啓動,並提供以下後錯誤消息:config/routes.r b:22:語法錯誤,意外的tASSOC,期待kEND:get =>:profile_avatar,:on =>:member^ – Brian

+0

抱歉,它不是':get',''profile_avatar''不是':profile_avatar' 。我放了太多符號:) – apneadiving

+0

給+1相關答案總是一個好習慣。我不乞求,雖然 – apneadiving

0
resources :accounts, :only => [:show, :new, :edit, :create, :update] do 
    member do 
    get :profile_avatar 
    end 
end