我被困住了。我需要你的帮助,拜托。即使我使用了经过验证的路径rake routes
user_queue_videos GET /users/:user_id/queue_videos(.:format) queue_videos#index
我收到以下错误:
ActionController::RoutingError at /videos
No route matches {:controller=>"queue_videos"}
视图中的链接
%li= link_to "My Queue", user_queue_videos_path
路线.rb
resources :users, only: [:new, :create] do
resources :queue_videos
end
queue_videos_controller
class QueueVideosController < ApplicationController
before_filter :require_user
def index
@videos = current_user.my_queued_videos
end
end
我尝试使用member routes
但它不起作用,所以我拿走了但它仍然没有呈现索引模板......
第二次尝试:当我放
class QueueVideosController < ApplicationController
before_filter :require_user
def index
@user.id = current_user.id #current_user is defined in ApplicationController
@videos = current_user.my_queued_videos
end
end
在视野中
%li= link_to "My Queue", user_queue_videos_path(@user.id)
它给了我以下错误:
RuntimeError at /videos
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
第三次尝试:然后我尝试了以下操作: 在视图中
%li= link_to "My Queue", user_queue_videos_path(current_user.id)
它给了我以下错误:
NoMethodError at /users/1/queue_videos
undefined method `id=' for nil:NilClass
注意:在 ApplicationController
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :logged_in?, :current_user
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def logged_in?
!!current_user
end
def require_user
unless logged_in?
flash[:error] = "You don't have permission to do this"
redirect_to root_path
end
end
end