【问题标题】:Rails ActionView::TemplateError (shop_url failed to generate fromRails ActionView::TemplateError(shop_url 无法从
【发布时间】:2011-05-15 06:42:30
【问题描述】:

我收到了,但我没有更改任何这些代码。我的开发环境运行良好。这发生在生产环境中。

当有匹配的条目时会发生这种情况。当没有匹配的条目时,没关系(显然!)。

Processing ShopsController#index (for 118.100.246.177 at 2010-11-25 01:46:48) [GET]
  Parameters: {"country"=>"France", "action"=>"index", "filter"=>"on", "order"=>"rating_descend", "type"=>"places", "controller"=>"shops", "keyword"=>""}
Rendering template within layouts/application
Rendering shops/index

ActionView::TemplateError (shop_url failed to generate from {:type=>"places", :action=>"show", :controller=>"shops"}, expected: {:controller=>"shops", :action=>"show"}, diff: {:type=>"places"}) on line #50 of app/views/shops/index.html.erb:
47: 
48:               <% @shops.each do |shop| %>
49:                 <div id="<%= dom_id(shop) %>" class="item">
50:                   <a href="<%= shop_path(shop, :type => @type) %>">
51:                     <% if !shop.photos.blank? %>
52:                       <%= image_tag(shop.photos.last.url(:thumb), :class => 'thumbnail') %>
53:                     <% else %>

    facebooker (1.0.75) lib/facebooker/rails/facebook_url_rewriting.rb:53:in `rewrite_url'
    facebooker (1.0.75) lib/facebooker.rb:200:in `request_for_canvas'
    facebooker (1.0.75) lib/facebooker/rails/facebook_url_rewriting.rb:52:in `rewrite_url'
    (eval):17:in `shop_path'
    app/views/shops/index.html.erb:50
    /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.20/lib/thinking_sphinx/search.rb:137:in `each'
    /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.20/lib/thinking_sphinx/search.rb:137:in `send'
    /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.20/lib/thinking_sphinx/search.rb:137:in `method_missing'
    app/views/shops/index.html.erb:48
    /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/authlogic-oauth-1.0.8/lib/oauth_callback_filter.rb:10:in `call'
    /opt/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/authlogic-oauth-1.0.8/lib/oauth_callback_filter.rb:10:in `call'
    passenger (2.2.15) lib/phusion_passenger/rack/request_handler.rb:92:in `process_request'
    passenger (2.2.15) lib/phusion_passenger/abstract_request_handler.rb:207:in `main_loop'
    passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:441:in `start_request_handler'
    passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:381:in `handle_spawn_application'
    passenger (2.2.15) lib/phusion_passenger/utils.rb:252:in `safe_fork'
    passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:377:in `handle_spawn_application'
    passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
    passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
    passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'
    passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:163:in `start'
    passenger (2.2.15) lib/phusion_passenger/railz/application_spawner.rb:222:in `start'
    passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:253:in `spawn_rails_application'
    passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:126:in `lookup_or_add'
    passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:247:in `spawn_rails_application'
    passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:80:in `synchronize'
    passenger (2.2.15) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
    passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:246:in `spawn_rails_application'
    passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:145:in `spawn_application'
    passenger (2.2.15) lib/phusion_passenger/spawn_manager.rb:278:in `handle_spawn_application'
    passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `__send__'
    passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:352:in `main_loop'
    passenger (2.2.15) lib/phusion_passenger/abstract_server.rb:196:in `start_synchronously'

Rendering template within layouts/application
Rendering errors/500.html.erb (500)
[paperclip] Saving attachments.

当我的type 是其他garagesmalls 等时,它们都运行良好。我什至重建了我的 Thinking Sphinx 索引。

更新 原来 MySQL ID 从 1、2、3 自动递增...我删除了 1、2、3 条目并将 ID 替换为 200000、200001、200002,这给了我问题。不知道 Rails 这么严格。

【问题讨论】:

  • 您是否有尚未保存的shop 对象?即这是在嵌套资源中,您在控制器操作中执行something.shops.build 吗?
  • 或者,您是否在 Shop 类上有自定义 to_param 方法,并且其中一家商店的 to_param 版本中是否包含句点 (.)?

标签: ruby-on-rails


【解决方案1】:

从错误消息中非常清楚。 :type => "places" 让你很伤心。如果您确实打算传递给控制器​​,您可能需要将 "?type=places 固定到生成的 URL 的末尾。

【讨论】:

  • 我觉得还不止这些……可能是一个尚未保存的 shop 对象。
  • 这是可能的。我没有在 params 哈希中看到任何暗示嵌套资源的内容,但我可能错过了一些东西。 OP:你为那条路线写过测试吗?
  • 该错误确实清楚地表明了这一点。要么使用不同的命名/嵌套路由,要么将其作为参数附加。
猜你喜欢
  • 2010-12-15
  • 2011-07-03
  • 2011-05-10
  • 1970-01-01
  • 2012-03-08
  • 1970-01-01
  • 2011-04-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多