首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从urlgenerationerror中的link_to结果创建新记录

从urlgenerationerror中的link_to结果创建新记录
EN

Stack Overflow用户
提问于 2018-08-13 19:25:23
回答 1查看 24关注 0票数 0

当用户单击链接时,我正尝试直接在表中创建一条记录。

但是,当它试图加载视图时,它会生成以下错误。

代码语言:javascript
复制
ActionController::UrlGenerationError in SopHeaders#show

No route matches {:action=>"create", :company_id=>2, :controller=>"sop_detail", :cost=>0.1e2, :cost_sop=>0.103e2, :customer_id=>1, :desc1=>"Printer cable YDP30 - Secura 224 ICEU", :flag_required=>true, :id=>"4", :list_price=>0.0, :opportunity_id=>"9", :product_code=>"01-69Y03293", :quantity=>1, :sophead_id=>4, :unit_price=>0.0}

我的观点

代码语言:javascript
复制
<%= link_to 'Add to Quote', {:controller => "sop_details", 
                       :action => "create", 
                       :sophead_id => @sop_header.id,
                       :customer_id => @customer.id,
                       :company_id => @customer.company_id, 
                       :product_code => stock.product_code, 
                       :unit_price => stock.price, 
                       :quantity => 1,
                       :cost => stock.cost, 
                       :cost_sop => stock.cost_sop, 
                       :list_price => stock.list_price, 
                       :flag_required => true, 
                       :desc1 => stock.desc1},
                       :method => "post" %>

我的控制器

代码语言:javascript
复制
  def new
    @sop_detail = SopDetail.new
  end


def create
    respond_to do |format|
      if @sop_detail.save
        format.html { redirect_to customer_opportunity_sop_header_path(@customer, @opportunity, @sop_header) }
        format.json { render :show, status: :created, location: @sop_header }
      else
        format.html { render :new }
        format.json { render json: @sop_header.errors, status: :unprocessable_entity }
      end
    end
end

我的路由表输出

代码语言:javascript
复制
    customer_opportunity_sop_header_sop_details GET    /customers/:customer_id/opportunities/:opportunity_id/sop_headers/:sop_header_id/sop_details(.:format)          sop_details#index
                                                POST   /customers/:customer_id/opportunities/:opportunity_id/sop_headers/:sop_header_id/sop_details(.:format)          sop_details#create
 new_customer_opportunity_sop_header_sop_detail GET    /customers/:customer_id/opportunities/:opportunity_id/sop_headers/:sop_header_id/sop_details/new(.:format)      sop_details#new
edit_customer_opportunity_sop_header_sop_detail GET    /customers/:customer_id/opportunities/:opportunity_id/sop_headers/:sop_header_id/sop_details/:id/edit(.:format) sop_details#edit
     customer_opportunity_sop_header_sop_detail GET    /customers/:customer_id/opportunities/:opportunity_id/sop_headers/:sop_header_id/sop_details/:id(.:format)      sop_details#show
                                                PATCH  /customers/:customer_id/opportunities/:opportunity_id/sop_headers/:sop_header_id/sop_details/:id(.:format)      sop_details#update
                                                PUT    /customers/:customer_id/opportunities/:opportunity_id/sop_headers/:sop_header_id/sop_details/:id(.:format)      sop_details#update

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2018-08-13 20:19:50

您的redirect_to路径不在您的路由中。当customer_opportunity_sop_header_path路径不在您的路由中时,您希望转到该路径。我猜您想要导航到customer_opportunity_sop_header_sop_details_path

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51821252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档