2012-08-22 52 views
0

所以我想有一個鏈接查找的方法在我的控制器,然後重定向到一個自定義頁面的路徑/試驗/ my_plays軌道3路由重定向錯誤:ID =>「routename」

我米收到錯誤: 在 「無法使用id = my_plays找到徑」, 「:48:應用程序/控制器/ trails_controller.rb在`節目」「

路線:

match '/trails/my_plays', :to => "trails#my_plays", :as => :my_plays 

鏈接:

<%= link_to "Your Trails", trails_my_plays_path %> 

控制器:

def show 
    @trail = Trail.find(params[:id]) #48 
    @member = Member.find(current_user.member_id) 
    respond_to do |format| 
     format.html # show.html.erb 
     format.json { render :json => @trail } 
    end 
    end 

def my_plays 
    @trails = Trail.all # once status is working, need to change to where(:publish => true) 
    @follower = Play.where(:member_id => current_user.member_id) 
    @member = Member.find(current_user.member_id) 
    @followed = [] #all trails followed by current user 
    @follows = [] #the play record for that trail 
    @trails.each do |trail| 
    if @follower.count > 0 
     @follower.each do |followr| 
     if (followr.trail_id == trail.id) 
        @followed << trail 
      @follows << followr 
     end 
    end 
    end 
end 
    respond_to do |format| 
     format.html { redirect_to "trails/my_plays" } 
    end 
end 
+0

那麼行數48是什麼? – melekes

+0

迴應@antonk您需要發佈演出活動的代碼。錯誤似乎來自重定向到「trails/my_plays」:'format.html {redirect_to「trails/my_plays」} –

回答

0

match你路由正被/trails路由,用於設置參數id取代。

trails(或其它匹配的路由,像:controller/:id)的資源路由需要經過路線匹配來,否則路由不會得到過去的第一路由匹配。

+0

我把它移開了,當我在rails服務器上查看頁面時,出現錯誤:No收到的數據 由於服務器未發送數據,無法加載網頁。 以下是一些建議: 稍後重新加載此網頁。 – HappaGirl

+0

嗯,現在它已經搞亂了我的路徑索引頁面,它正在尋找my_plays方法。可能是因爲新的路線正在取代索引資源。 – HappaGirl

+0

好吧,我明白了。我將資源移動回來後,將路由改爲/ my_plays而不是/ trails/my_plays,然後在控制器方法中刪除了重定向。 – HappaGirl