Ruby on rails 没有路由匹配{:controller=>;“queue”videos";}甚至我使用了rake路由的路径
我被卡住了。我需要你的帮助。 即使我使用了通过Ruby on rails 没有路由匹配{:controller=>;“queue”videos";}甚至我使用了rake路由的路径,ruby-on-rails,resources,controller,routes,Ruby On Rails,Resources,Controller,Routes,我被卡住了。我需要你的帮助。 即使我使用了通过rake路由验证的路径 user_queue_videos GET /users/:user_id/queue_videos(.:format) queue_videos#index 我得到了以下错误: ActionController::RoutingError at /videos No route matches {:controller=>"queue_videos"} RuntimeError at /vi
rake路由验证的路径
user_queue_videos GET /users/:user_id/queue_videos(.:format) queue_videos#index
我得到了以下错误:
ActionController::RoutingError at /videos
No route matches {:controller=>"queue_videos"}
RuntimeError at /videos
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
NoMethodError at /users/1/queue_videos
undefined method `id=' for nil:NilClass
视图中的链接
%li= link_to "My Queue", user_queue_videos_path
routes.rb
resources :users, only: [:new, :create] do
resources :queue_videos
end
队列\u视频\u控制器
class QueueVideosController < ApplicationController
before_filter :require_user
def index
@videos = current_user.my_queued_videos
end
end
鉴于
%li= link_to "My Queue", user_queue_videos_path(@user.id)
它给了我以下错误:
ActionController::RoutingError at /videos
No route matches {:controller=>"queue_videos"}
RuntimeError at /videos
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
NoMethodError at /users/1/queue_videos
undefined method `id=' for nil:NilClass
第三次尝试:然后我尝试了以下内容:
鉴于
它给了我以下错误:
ActionController::RoutingError at /videos
No route matches {:controller=>"queue_videos"}
RuntimeError at /videos
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
NoMethodError at /users/1/queue_videos
undefined method `id=' for nil:NilClass
注意:
在应用程序控制器中
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
class ApplicationController
根据您的rake routes
输出和routes.rb
您需要传递用户id
,因为您是用户的成员。例如:
%li= link_to "My Queue", user_queue_videos_path(current_user.id)
希望这有帮助 哦,我也试过了,但它也给了我一个错误:为nil调用id,它会错误地为4——如果您真的想要nil的id,请使用object_id,这是因为@user没有定义。您需要定义它。
@user.id
只是一个例子。我现在不知道如何在您的视图中获取用户id。请尝试:user\u queue\u videos\u path(current\u user.id)
确保您的current\u user
不为零。也许你没有登录。