为什么Delete链接在这个Ruby on Rails项目中不起作用? [英] Why Delete link doesn't work in this Ruby on Rails project?

查看:79
本文介绍了为什么Delete链接在这个Ruby on Rails项目中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在练习Michael Hartl的这个RoR教程项目: http:// ruby .railstutorial.org / ruby​​-on-rails-tutorial-book

I am practicing this RoR tutorial project of Michael Hartl: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

我在Ubuntu 11.04上用Apache和MySQL使用Ruby 1.9.2和Rails 3.1 。

I am using Ruby 1.9.2 and Rails 3.1 on Ubuntu 11.04 with Apache and MySQL.

我现在在这里: http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#sec:destroying_users (我有用户列表和删除链接他们每个人,我都是管理员。)

I am here now: http://ruby.railstutorial.org/chapters/updating-showing-and-deleting-users#sec:destroying_users (where I have s list of users and a Delete link for each of them, me being the admin).

这是应该有效的删除链接:

This is the delete link which supposed to work:

<%= link_to "delete", user, :method => :delete, :confirm => "You sure?",
                            :title => "Delete #{user.name}" %>

但当我鼠标悬停时,我看到:localhost / users / 2(例如)
当我点击删除链接时,它会将我引导至用户的个人资料。我没有得到任何确认窗口,也没有进行任何操作(删除)。这就像是他们个人资料的链接而已。
我使用Chrome但在Firefox中是相同的。

But when I mouseover I see this: "localhost/users/2" (for example) And when I click on the Delete link it directs me to the user's profile. I don't get any confirmation window and no action is done (delete). It's like a link to their profile and nothing else. I am using Chrome but in Firefox is the same.

这就是我所拥有的:

1)安装了宝石jquery-rails

1)the gem "jquery-rails" is installed

2)applications.js(来自app / assets / javascripts)有这些行:

2)applications.js (from app/assets/javascripts) has these lines:

//= require jquery
//= require jquery_ujs
//= require_tree .

3)application.html.erb(来自app / views / layouts)有这些行:

3)application.html.erb (from app/views/layouts) has these lines:

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tags %>

在视图来源中,我看到:

In view source I see:

  <script src="/assets/defaults.js" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
  <meta content="njPO91rB7p3EtTblD4jf4rkCVt+M76SKUt0rQhHc+qY=" name="csrf-token" />

4)(来自app / controllers)我有:

4)in users_controllers.rb (from app/controllers) I have:

 before_filter :authenticate, :only => [:index, :edit, :update, :destroy]
 before_filter :correct_user, :only => [:edit, :update]
 before_filter :admin_user,   :only => :destroy

 def destroy
  User.find(params[:id]).destroy
  flash[:success] = "User destroyed."
  redirect_to users_path
 end

 private
  def admin_user
    redirect_to(root_path) unless current_user.admin?
  end

5)routes.rb(来自配置)我有:

5)in routes.rb (from config) I have:

resources :users

删除链接有什么问题?
我搜索了StackOverflow的答案,但显然我找不到适合我的情况。

What is wrong with that Delete link? I've searched StackOverflow for answers but apparently I couldn't find one to suit my situation.

在同一个RoR项目中,使用关闭/取消关注按钮Ajax工作得很好(暂时不能在这里发布第二个链接,因为我刚注册到SO)。

On the same RoR project the follow/unfollow button using Ajax works just fine (can't post a second link here for now because I just registered to the SO).

那么,为什么链接不起作用?这是一个Javascript问题还是其他一些我没看到的问题?

So, why the link doesn't work? Is it a Javascript problem or some other problem which I am not seeing?

谢谢。

推荐答案

尝试使用

  <%= javascript_include_tag "application" %>

而不是:默认

这篇关于为什么Delete链接在这个Ruby on Rails项目中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆