rails 3 route redirect error:id => “routename”

时间:2012-08-22 16:58:26

标签: ruby-on-rails-3 custom-routes

所以我正在尝试在我的控制器中查找一个方法,然后使用路径/试验/ my_plays重定向到自定义页面

我收到错误: “无法在”app / controllers / trails_controller.rb:48:in`show'中找到具有id = my_plays的Trail“

路线:

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

1 个答案:

答案 0 :(得分:0)

您的match路由被设置/trails参数的id路由取代。

trails(或其他匹配路由,如:controller/:id)的资源路由需要路由匹配后,否则路由将不会超过第一个路线匹配。