2011-04-12 3 views
0

내 동영상 컨트롤러에서이 사용자 지정 작업이 있습니다내 앱이이 맞춤보기로 이동하도록하려면 어떻게해야하나요?

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" %> 

및 전망

def upvoted_songs 
    @votes = current_user.videos_votes.where("value = 1") 
    @videos = @votes.videos.page(params[:page]).per(15) 
end 

이 내 경로입니다 videos/upvoted_songs.html.erb라는 파일

왜 링크가 upvoted_songs.html.erb보기로 연결되지 않고 비디오 색인보기로 유지됩니까?

UPDATE :이 내 routes.rb입니다

:

ArgumentError 

can't use member outside resource(s) scope 

은 다음 페이지를 새로 고침 한 후, 나는이 오류가 :

나는 처음에이 오류가

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 

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" %> 
+0

호기심 : @votes = current_user.videos_votes.where ("value = 1")는> 1이 아니어야합니까? : P – corroded

+0

아니, 왜냐하면 나는 사용자가 upvoted 모든 비디오를 검색하고 싶은데 내 앱에서 투표의 가치가 1 일 때이다. :) –

+0

나는 당신이 모든 upvoted 투표를하고 싶다고 생각했다. 하지만 부울은 1보다 낫지 않습니까? 다시 물어보십시오 :) – corroded

답변

3

앱에서 사용할 수있는 경로는 앱의 루트 디렉토리에있는 명령 행에서 rake routes입니다. upvoted_songs을 나타내는 행이 표시되어야합니다.

은 다음과 같이 사용 :

당신이이 회원 경로가 가지고 있기 때문에
<%= link_to "Upvoted Songs", upvoted_songs_video_path(video), :class => "upvoted_songs chosen_home_option" %> 

과 같이 보이는 URL을 비디오 객체 (또는 ID)를 받아 생성되는 URL 도우미 : /videos/7/upvoted_songs

그러나 코드는 단일 비디오 객체에 의존하지 않는 작업을 수행 중이라고 제안합니다. URL에 해당 객체가 필요하지는 않습니다. 따라서 경로를 경로에서 콜렉션 경로로 변경하고 싶을 것입니다. 그러면 URL은 /videos/upvoted_songs과 같이 보이게되고 비디오 객체를 전달하지 않게됩니다.

resources :videos do 
    resources :comments 
    put 'topic_update', :on => :member 
    get 'upvoted_songs', :on => :collection, :as => 'upvoted' 
end 
+0

덕분에, 어떻게 그것을 수집 경로로 바꿀 수 있을까? 그게 내가 원하는거야. –

+1

아래 coreyward 답을 확인해보십시오. – ctcherry

+0

@Justin 제가 예제를 게시했습니다. 이 물건을 잊었을 때 라우팅 가이드를 다시 확인할 수 있습니다. 꽤 포괄적입니다. http://guides.rubyonrails.org/routing.html – coreyward

1

당신은 ID가없는 :이 도움이

희망 :

PART

2는 회원 블록을 제거합니다. 갈퀴 루트 | grep upvoted하고 경로가 어떻게 생겼는지 확인하십시오.

아마 upvoted_songs_video_path(video)

2

당신은 "동영상 # 지수"에 대한 도우미입니다 videos_path에 연결하는 같은입니다.

ctcherry가 설명했듯이 현재 경로가 회원 경로이며 컬렉션이 아닙니다.그런 다음 당신은 그냥 videos_path 대신에 upvoted_videos_path을 사용할 수 있습니다

resources :videos do 
    put 'topic_update', :on => :member 
    get 'upvoted_songs', :on => :collection, :as => 'upvoted' 
end 

: 다음은 당신이 찾고있는 더 많은 것이다.

+0

감사합니다. 귀하의 코드가 나를 위해이 오류를 던졌습니다 :'ArgumentError 리소스 범위 밖에서 회원을 사용할 수 없습니다'이것은 무엇을 의미합니까? –

+0

'resources'에게 전달되는 블록 안에'put 'topic_update', : on => : member' 호출이 있는지 확인하십시오. 그리고 이와 관련하여 언급 된 ctcherry와 마찬가지로 콜론을 놓치지 않았는지 확인하십시오. – coreyward

+0

오류에 대한 자세한 내용과 함께 질문 세부 정보를 업데이트했습니다. –

관련 문제