我最近做了这个教程http://www.reinteractive.net/posts/32-ruby-on-rails-3-2-blog-in-15-minutes-step-by-step,但是我很难弄清楚如何在发布评论后删除评论,我已经尝试了
方法但不起作用
它只是向我返回未定义的方法错误,我做错了什么
我的代码:
<%= div_for rep do %>
<p>
<div style="font-weight:bold; color:grey;"><%= rep.title %></div>
<div><%= rep.body %></div>
<strong style="font-size:8px;">
Posted <%= time_ago_in_words(rep.created_at) %> ago
</strong>
<br/>
<%= link_to 'Destroy', steppy_reps_path(@steppy, rep), method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
<% end %>
错误: 没有路线匹配[DELETE]&#34; /steppies/11/reps.9"
routes.rb中:
Testapp2::Application.routes.draw do
resources :steppies do
resources :reps, :only => [:create]
end
get "steppies/ask"
get "steppies/create"
get "steppy/ask"
get "steppy/create"
end
rake route output:
steppy_reps POST /steppies/:steppy_id/reps(.:format) reps#create
steppy_rep DELETE /steppies/:steppy_id/reps/:id(.:format) reps#destroy
steppies GET /steppies(.:format) steppies#index
POST /steppies(.:format) steppies#create
new_steppy GET /steppies/new(.:format) steppies#new
edit_steppy GET /steppies/:id/edit(.:format) steppies#edit
steppy GET /steppies/:id(.:format) steppies#show
PUT /steppies/:id(.:format) steppies#update
DELETE /steppies/:id(.:format) steppies#destroy
steppies_ask GET /steppies/ask(.:format) steppies#ask
teppies_create GET /steppies/create(.:format) steppies#create
steppy_ask GET /steppy/ask(.:format) steppy#ask
steppy_create GET /steppy/create(.:format) steppy#create
答案 0 :(得分:1)
您需要将操作添加到routes.rb
文件中。
resources :steppies do
resources :reps, :only => [:create, :destroy]
end
此外,表单需要使用不同的路径。
steppy_rep_path(@steppy, rep)