我是Ruby On Rails的新手,并通过this guide构建基本应用程序。
当我尝试实现文档中提到的删除功能时,我会看到显示页面。
我的控制器中有以下方法:
def destroy
@article = Article.find(params[:id])
@article.destroy
redirect_to articles_path
end
以及我页面中的以下行:
<td><%= link_to 'Destroy', article_path(article),
method: :delete,
data: { confirm: 'Are you sure?' } %></td>
现在当我点击链接时,我在浏览器中看到以下网址:
现在,在这种情况下,我看到的是显示屏幕,而不是收到警告消息,然后从我的页面中删除记录。
我已关注此SO帖子 - Rails 4 link_to Destroy not working in Getting Started tutorial
并验证了
//= require jquery
//= require jquery_ujs
我的application.js
中有个元素
请告诉我我在哪里做错了?
更新
这是rake routes
命令的输出:
E:\Rails\blog\bin>rake routes
(in E:/Rails/blog)
Prefix Verb URI Pattern Controller#Action
welcome_index GET /welcome/index(.:format) welcome#index
articles GET /articles(.:format) articles#index
POST /articles(.:format) articles#create
new_article GET /articles/new(.:format) articles#new
edit_article GET /articles/:id/edit(.:format) articles#edit
article GET /articles/:id(.:format) articles#show
PATCH /articles/:id(.:format) articles#update
PUT /articles/:id(.:format) articles#update
DELETE /articles/:id(.:format) articles#destroy
root GET / welcome#index
这是我点击删除链接时从日志文件中获取的内容:
Started GET "/articles/3" for 127.0.0.1 at 2015-05-09 00:56:08 +0530
Processing by ArticlesController#show as HTML
Parameters: {"id"=>"3"}
[1m[35mArticle Load (0.0ms)[0m SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT 1 [["id", 3]]
Rendered articles/show.html.erb within layouts/application (0.0ms)
Completed 200 OK in 47ms (Views: 46.9ms | ActiveRecord: 0.0ms)
在我的application.html.erb
文件中,我已将文字application
修改为default
以修复我在此帖中报告的问题 - ExecJS::ProgramError in Welcome#index TypeError: Object doesn't support this property or method,这是导致我现在的问题?如果还原更改,则应用程序完全失败。
答案 0 :(得分:2)
您必须使用link_to
代替param ([string[]]$DeployModules)
Switch -Regex ($DeployModules)
{
'Base|All'
{
'deploy Base module'
}
'Pack1|All'
{
'deploy Pack1 module'
}
'Pack3|All'
{
'deploy Pack3 module'
}
}
才能使其正常运行。
请参阅此帖 - Rails 3 - link_to :delete is redirecting to show action with jquery installed,查看Cypher给出的答案。