Ruby on rails 3 删除链接调用显示方法
当我在帖子索引页面上点击一篇帖子的删除链接时,我不断收到显示操作的GET请求,而不是调用销毁操作。因此,读取未知操作时出错-找不到PostsController的操作“show” 我认为问题在于我有嵌套的路由,而不是常规路由 我看了谷歌和StackOverflow上的很多帖子,但没有一个答案对我有帮助。有什么建议吗 app/views/posts/index.html.erbRuby on rails 3 删除链接调用显示方法,ruby-on-rails-3,nested,Ruby On Rails 3,Nested,当我在帖子索引页面上点击一篇帖子的删除链接时,我不断收到显示操作的GET请求,而不是调用销毁操作。因此,读取未知操作时出错-找不到PostsController的操作“show” 我认为问题在于我有嵌套的路由,而不是常规路由 我看了谷歌和StackOverflow上的很多帖子,但没有一个答案对我有帮助。有什么建议吗 app/views/posts/index.html.erb <% @posts.each do |post| %> <tr> <td>
<% @posts.each do |post| %>
<tr>
<td><%= post.content %></td>
<td>Username_placeholder</td>
<td><%= post.created_at %></td>
<td><%= link_to 'Delete', topic_post_path(@topic, post), confirm: 'Are you sure?', method: :delete %></td>
<!-- topic_post_path(@topic,post) -->
</tr>
<% end %>
app/models/topic.rb
class Topic < ActiveRecord::Base
has_many :posts, :dependent => :destroy
belongs_to :forum
accepts_nested_attributes_for :posts, :allow_destroy => true
attr_accessible :name, :last_post_id, :posts_attributes
end
所有路线
root / forums#index
forum_topics GET /forums/:forum_id/topics(.:format) topics#index
POST /forums/:forum_id/topics(.:format) topics#create
new_forum_topic GET /forums/:forum_id/topics/new(.:format) topics#new
edit_forum_topic GET /forums/:forum_id/topics/:id/edit(.:format) topics#edit
forum_topic GET /forums/:forum_id/topics/:id(.:format) topics#show
PUT /forums/:forum_id/topics/:id(.:format) topics#update
DELETE /forums/:forum_id/topics/:id(.:format) topics#destroy
forums GET /forums(.:format) forums#index
POST /forums(.:format) forums#create
new_forum GET /forums/new(.:format) forums#new
edit_forum GET /forums/:id/edit(.:format) forums#edit
forum GET /forums/:id(.:format) forums#show
PUT /forums/:id(.:format) forums#update
DELETE /forums/:id(.:format) forums#destroy
topic_posts GET /topics/:topic_id/posts(.:format) posts#index
POST /topics/:topic_id/posts(.:format) posts#create
new_topic_post GET /topics/:topic_id/posts/new(.:format) posts#new
edit_topic_post GET /topics/:topic_id/posts/:id/edit(.:format) posts#edit
topic_post GET /topics/:topic_id/posts/:id(.:format) posts#show
PUT /topics/:topic_id/posts/:id(.:format) posts#update
DELETE /topics/:topic_id/posts/:id(.:format) posts#destroy
topics GET /topics(.:format) topics#index
POST /topics(.:format) topics#create
new_topic GET /topics/new(.:format) topics#new
edit_topic GET /topics/:id/edit(.:format) topics#edit
topic GET /topics/:id(.:format) topics#show
PUT /topics/:id(.:format) topics#update
DELETE /topics/:id(.:format) topics#destroy
链接到'Delete',[@topic,post],确认:'you sure',method::Delete?请提供Rails生成的Delete链接的HTML代码。应用程序中是否有其他删除链接?布局中是否包含application.js?application.js为空?实际上,所有这些数据。。。是javascript的魔力,因此需要“jquery_ujs”
class Post < ActiveRecord::Base
belongs_to :topic
attr_accessible :content
end
Minforum::Application.routes.draw do
root :to => "forums#index"
resources :forums do
resources :topics
end
resources :topics do
resources :posts
end
end
root / forums#index
forum_topics GET /forums/:forum_id/topics(.:format) topics#index
POST /forums/:forum_id/topics(.:format) topics#create
new_forum_topic GET /forums/:forum_id/topics/new(.:format) topics#new
edit_forum_topic GET /forums/:forum_id/topics/:id/edit(.:format) topics#edit
forum_topic GET /forums/:forum_id/topics/:id(.:format) topics#show
PUT /forums/:forum_id/topics/:id(.:format) topics#update
DELETE /forums/:forum_id/topics/:id(.:format) topics#destroy
forums GET /forums(.:format) forums#index
POST /forums(.:format) forums#create
new_forum GET /forums/new(.:format) forums#new
edit_forum GET /forums/:id/edit(.:format) forums#edit
forum GET /forums/:id(.:format) forums#show
PUT /forums/:id(.:format) forums#update
DELETE /forums/:id(.:format) forums#destroy
topic_posts GET /topics/:topic_id/posts(.:format) posts#index
POST /topics/:topic_id/posts(.:format) posts#create
new_topic_post GET /topics/:topic_id/posts/new(.:format) posts#new
edit_topic_post GET /topics/:topic_id/posts/:id/edit(.:format) posts#edit
topic_post GET /topics/:topic_id/posts/:id(.:format) posts#show
PUT /topics/:topic_id/posts/:id(.:format) posts#update
DELETE /topics/:topic_id/posts/:id(.:format) posts#destroy
topics GET /topics(.:format) topics#index
POST /topics(.:format) topics#create
new_topic GET /topics/new(.:format) topics#new
edit_topic GET /topics/:id/edit(.:format) topics#edit
topic GET /topics/:id(.:format) topics#show
PUT /topics/:id(.:format) topics#update
DELETE /topics/:id(.:format) topics#destroy