为什么我收到此路由错误?

时间:2022-02-28 22:46:53

Whenever I use job_medium_path I receive this routing error:

每当我使用job_medium_path时,我都会收到此路由错误:

ActionController::RoutingError Exception: No route matches {:action=>"show", :controller=>"media"}

However, when I use rake routes it clearly shows that there is a route for that path:

但是,当我使用rake路线时,它清楚地表明该路径有一条路线:

job_medium GET    /jobs/:job_id/media/:id(.:format)       {:action=>"show", :controller=>"media"}

Also, in the media controller the show action is defined.

此外,在媒体控制器中定义了show动作。

Other routes and paths for this controller work perfectly, including:

该控制器的其他路径和路径完美运行,包括:

job_media GET    /jobs/:job_id/media(.:format)            {:action=>"index", :controller=>"media"}
new_job_medium GET    /jobs/:job_id/media/new(.:format)   {:action=>"new", :controller=>"media"}

When I call the path on a page I use: job_medium_path(@mediumable, @media) and receive this error:

当我在页面上调用路径时,我使用:job_medium_path(@mediumable,@ media)并收到此错误:

Routing Error

No route matches {:action=>"show", :controller=>"media", :job_id=>[all job info is here]}

没有路由匹配{:action =>“show”,:controller =>“media”,:job_id => [所有工作信息都在这里]}

Also here is the action:

这里还有一个动作:

def show
  @medium = @mediumable.media.find(params[:id])
end

2 个解决方案

#1


0  

You have to provide the job and medium id, something like this:

你必须提供工作和中等ID,如下所示:

job_medium_path(@job, @medium)

#2


0  

Supossing @job and @medium exist, try this:

存在@job和@medium,试试这个:

job_medium_path(job_id: @job.id, id: @medium.id)

#1


0  

You have to provide the job and medium id, something like this:

你必须提供工作和中等ID,如下所示:

job_medium_path(@job, @medium)

#2


0  

Supossing @job and @medium exist, try this:

存在@job和@medium,试试这个:

job_medium_path(job_id: @job.id, id: @medium.id)