0

所以我试图让一个链接在我的控制器中查找一个方法,然后重定向到一个带有路径 /trials/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
4

1 回答 1

0

您的路线正在被设置参数match的路线所取代。/trailsid

trails(或其他匹配路由,如)的资源路由:controller/:id需要您的路由匹配器之后,否则路由将无法通过第一个路由匹配。

于 2012-08-23T02:32:56.540 回答