"stages"} 对应这一行: ".html_safe, send_to_client_-6ren">
gpt4 book ai didi

ruby-on-rails - 对于存在的路由,为什么我会得到 'no route matches' ?

转载 作者:行者123 更新时间:2023-12-04 03:36:36 24 4
gpt4 key购买 nike

这是错误:

没有路由匹配 {:action=>"send_to_client", :controller=>"stages"}

对应这一行:

<%= link_to "<span class='icon send-to-client-icon' title='Send to Client' id='send-to-client'> </span>".html_safe, send_to_client_stage_path(@stage), :id => stage.id, :confirm => "This will send #{stage.name.capitalize} to #{stage.client.email}. Are you sure you are ready?" %>

在此_show_table.html.erb

<%

if @upload != nil
stage = @upload.stage
end

%>
<h1 class="panel-header">Images</h1>

<% if stage == nil %>
<div class="images_menu">
<%= link_to "<span class='icon send-to-client-icon' title='Send to Client' id='send-to-client'> </span>".html_safe, send_to_client_stage_path(@stage), :id => stage.id, :confirm => "This will send #{stage.name.capitalize} to #{stage.client.email}. Are you sure you are ready?" %>
<span class="icon compare-icon" data-url="<%= compare_stage_path(stage)%>" title="Compare Images" id="compare-images"> </span>
</div>
<% end %>

这是我的routes.rb:

resources :stages do
member do
get :step
get :compare
get :send_to_client
end
end

问题是这部分_show_table.html.erb位于我的uploads模型的 View 文件夹中......而不是stages型号。

当我在 stages 模型中执行 link_to 时,它工作正常。一旦我将其放入 uploads 模型中,它就会抛出该错误。

为什么会这样?

Edit1:这是 stages Controller 的 send_to_client 操作:

def send_to_client
stage = Stage.find(params[:id])
ClientMailer.send_stage(stage).deliver
if ClientMailer.send_stage(stage).deliver
flash[:notice] = "Successfully sent to client."
redirect_to("/")
else
flash[:notice] = "There were problems, please try re-sending."
redirect_to("/")
end
end

最佳答案

如果您使用send_to_client_stage_path(nil),Rails 将引发 ActionController::RoutingError。

您混淆了@stagestage。如果您没有在 Controller 操作中定义 @stage ,则它将是 nil 并引发错误。在这种情况下,只需使用@upload.stage

喜欢:

<% if @upload.stage %>
<%= link_to "...", send_to_client_stage_path(@upload.stage), :confirm => "..." %>
<% end %>

如果您想使用@stage,只需在操作中使用@stage = @upload.stage 定义它,然后使用它来代替@upload。阶段:

<% if @stage %>
<%= link_to "...", send_to_client_stage_path(@stage), :confirm => "..." %>
<% end %>

关于ruby-on-rails - 对于存在的路由,为什么我会得到 'no route matches' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5798090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com