Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 为什么这个嵌套的资源链接“U到查找”呢;“销毁”;而不是",;显示“;?_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 为什么这个嵌套的资源链接“U到查找”呢;“销毁”;而不是",;显示“;?

Ruby on rails 3 为什么这个嵌套的资源链接“U到查找”呢;“销毁”;而不是",;显示“;?,ruby-on-rails-3,Ruby On Rails 3,我只是想让链接指向“user/1/post/1”。我尝试过使用link_to,使用和不使用:method键,得到了相同的结果 ActionController::RoutingError in Posts#index Showing /home/test/rails_apps/test_app/app/views/posts/index.html.erb where line #22 raised: No route matches {:action=>"destroy", :cont

我只是想让链接指向“user/1/post/1”。我尝试过使用link_to,使用和不使用:method键,得到了相同的结果

ActionController::RoutingError in Posts#index

Showing /home/test/rails_apps/test_app/app/views/posts/index.html.erb where line #22 raised:

No route matches {:action=>"destroy", :controller=>"posts", :user_id=>#<Post id: 1, content: "wtf", user_id: 1, created_at: "2010-10-27 20:46:46", updated_at: "2010-10-27 20:46:46">}

Extracted source (around line #22):

22:     <td><%= link_to 'Show', user_post_path(p), :method => :get %></td>
ActionController::Posts中的路由错误#索引
显示/home/test/rails_apps/test_app/app/views/posts/index.html.erb,其中第22行出现:
没有路由匹配{:action=>“destroy”,:controller=>“posts”,:user_id=>#}
提取的源(第22行附近):
22::获取%>

小心使用“:method”参数。它指定了一个HTTP方法,而不是操作。

您使用的是
user\u post\u path(p)
我猜
p=>post对象

但是此路由还需要一个用户对象,因此此资源将计算为用户的帖子

看看

上面说

In addition to using the routing helpers, Rails can also create paths and URLs from an array of parameters. For example, suppose you have this set of routes:

resources :magazines do
  resources :ads
end

When using magazine_ad_path, you can pass in instances of Magazine and Ad instead of the numeric IDs.
<%= link_to "Ad details", magazine_ad_path(@magazine, @ad) %>

You can also use url_for with a set of objects, and Rails will automatically determine which route you want:
<%= link_to "Ad details", url_for([@magazine, @ad]) %>
除了使用路由帮助器,Rails还可以从一组参数创建路径和URL。例如,假设您有以下一组路由:
资源:杂志可以
资源:广告
结束
当使用magazine_ad_path时,可以传入magazine和ad的实例,而不是数字ID。
您还可以将url_用于一组对象,Rails将自动确定您想要的路由:

希望这有帮助。

好的。我把它改为:get from:show,它仍然在寻找销毁路线。我认为这仍然是一个问题,我只是想确保这不是导致它的一个问题。我也投了更高的票,因为我也不完全明白为什么会发生这种情况。你能在第22行的周围再贴一些上下文吗?