没有路线匹配{:action =>“show”,:controller =>“spree / taxons”,:id => nil}

时间:2018-04-12 05:36:51

标签: ruby-on-rails spree-upgrade

Hello RoR程序员,

我被卡在定制的狂欢应用程序代码中,在升级到rails 5.1.5后出现错误。

puma记录了这个错误:

  

故障安全响应期间出错:没有路由匹配{:action =>“show”,   :controller =>“spree / taxons”,:id => nil},可能无法比拟   约束:[:id]
  /root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/journey/formatter.rb:55:in   generate'
/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/routing/route_set.rb:748:in
生成'
  /root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/routing/route_set.rb:779:in   generate'
/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/routing-filter-0.6.1/lib/routing_filter/adapters/rails.rb:30:in
阻止生成'
  /root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/routing-filter-0.6.1/lib/routing_filter/filters/locale.rb:70:in   around_generate'
/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/routing-filter-0.6.1/lib/routing_filter/filter.rb:11:in
运行'
  /root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/routing-filter-0.6.1/lib/routing_filter/chain.rb:15:in   run'
/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/routing-filter-0.6.1/lib/routing_filter/adapters/rails.rb:29:in
生成'
  /root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/routing/route_set.rb:826:in   url_for'
/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/routing/route_set.rb:277:in
称之为'
  /root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/routing/route_set.rb:335:in   block (2 levels) in define_url_helper'
/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/routing/routes_proxy.rb:42:in
nested_taxons_path'
  /root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/actionpack-5.1.5/lib/action_dispatch/routing/routes_proxy.rb:45:in   method_missing'
/root/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/spree_core-3.4.4/app/helpers/spree/base_helper.rb:79:in
seo_url'
  /home/ypill/wuxu18/app/views/spree/frontend/ypill/_main_nav_bar.html.erb:16:in   `_ block(3级)in _d16a1d9612a1846710427ba2d762257f'

应用程序/控制器/礼包/ taxons_controller.rb:

module Spree
  class TaxonsController < Spree::StoreController
    helper 'spree/products', 'spree/taxon_filters'

    respond_to :html

    def show
      @taxon = Taxon.friendly.find(params[:id])
      return unless @taxon

      @searcher = build_searcher(params.merge(taxon: @taxon.id, include_images: true))
      @products = @searcher.retrieve_products
      @taxonomies = Spree::Taxonomy.includes(root: :children)

热潮/前端/配置/ routes.rb中:

  # route globbing for pretty nested taxon and product paths
  get '/t/*id', to: 'taxons#show', as: :nested_taxons

在spree / core / app / helpers / spree / base_helper.rb中:

def seo_url(taxon)
  spree.nested_taxons_path(taxon.permalink)
end

第79行:spree.nested_taxons_path(taxon.permalink) method_missing' or undefined method永久链接'为零:NilClass

自定义_main_nav_bar.html.erb文件代码,从第16,14,13行开始记录错误:

<% @taxonomies ||= Spree::Taxonomy.includes(root: :children)  %>
<% max_level = Spree::Config[:max_level_in_taxons_menu] || 1 %>
<div class="navbar-header">
      <div class="container">
         <nav class="navbar" id="cssmenu">
          <ul class="navbar-nav">
            <li id="home-link"
            class="<%= ('active' if @page.nil? && @taxon.id == 12) unless @taxon.nil? %>"
              data-hook><%= link_to Spree.t(:home), spree.root_path %></li>

            <%#= @taxon.inspect %>
            <% @taxonomies.each do |taxonomy| %>
              <% cache [I18n.locale, taxonomy, max_level] do %>
                    <% taxonomy.root.children.each do |taxon| %>
                      <li class="<%= (taxon.id == @taxon.id ? 'active' : '') unless @taxon.nil? %>">
                        <%= link to taxon.name, seo_url(taxon) %>">
                        </a>
                      </li>
                    <% end %>
                <% end %>
            <% end %>
          </ul>

        </nav>

第12行:

<% @taxonomies.each do |taxonomy| %>

第13行:

<% cache [I18n.locale, taxonomy, max_level] do %>

第14行:

<% taxonomy.root.children.each do |taxon| %>

第16行

<%= link to taxon.name, seo_url(taxon) %>

在块(3级)中,puma寻找'seo_url'到spree_core-3.4.4 / app / helpers / spree / base_helper.rb:79'spree.nested_taxons_path(taxon.permalink)'方法丢失。

main_nav_bar.html.erb在rails 4.2上工作。

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

尝试这条路线:

 get '/t/*id', to: 'spree/taxons#show', as: :nested_taxons