我有這樣的自定義操作在我的視頻控制器:如何讓我的應用程序轉到此自定義視圖?
def upvoted_songs
@votes = current_user.videos_votes.where("value = 1")
@videos = @votes.videos.page(params[:page]).per(15)
end
這是我的路線:
resources :videos do
member do
put 'topic_update'
get 'upvoted_songs'
end
end
而這個鏈接在我的視頻索引視圖:
<%= link_to "Upvoted Songs", videos_path, :action => "upvoted_songs", :class => "upvoted_songs chosen_home_option" %>
和視圖文件稱爲videos/upvoted_songs.html.erb。
爲什麼不直接鏈接到upvoted_songs.html.erb視圖,而是停留在視頻索引視圖上?
UPDATE:
這些是我的routes.rb:
root :to => "videos#index"
resources :video_votes
resources :videos do
resources :comments
member do
put 'topic_update', :on => :member
get 'upvoted_songs', :on => :collection, :as => 'upvoted'
end
end
resources :comment_titles
resources :users
resources :profiles
resources :genres
resources :topics
resources :topicables
resource :session
我最初得到這個錯誤:
ArgumentError
can't use member outside resource(s) scope
然後刷新頁面後,我得到這個錯誤:
ActionController::RoutingError in Videos#index
Showing /rubyprograms/dreamstill/app/views/videos/_video.html.erb where line #22 raised:
No route matches {:action=>"show", :id=>#<Video id: 485, title: "I'm Ready For You", description: nil, embed_code: nil, thumbnail_url: nil, released: nil, user_id: 57, created_at: "2011-04-02 08:47:36", updated_at: "2011-04-09 22:42:48", video_url: "http://www.youtube.com/watch?v=wy86KNtOjVg", video_votes_count: 0, vote_sum: 3, rank_sum: 28927.724512>, :controller=>"videos"}
22: <%= link_to video.title, video_path(video), :class => "normal" %>
只是好奇:@votes = current_user.videos_votes.where(「value = 1」)應該不是> 1? :P – corroded 2011-04-12 03:29:35
不,因爲我想檢索用戶已投票的所有視頻,而在我的應用程序中,當投票的值爲1時: – 2011-04-12 03:32:12
我看到了,我以爲你想獲得所有最高投票。但是沒有布爾比1更好?只是再次詢問:) – corroded 2011-04-12 03:33:52