I am practicing this RoR tutorial project of Michael Hartl: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
I am using Ruby 1.9.2 and Rails 3.1 on Ubuntu 11.04 with Apache and MySQL.
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}" %>
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.
This is what I have:
1)the gem "jquery-rails" is installed
2)applications.js (from app/assets/javascripts) has these lines:
//= require jquery
//= require jquery_ujs
//= require_tree .
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)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)in routes.rb (from config) I have:
resources :users
What is wrong with that Delete link? I've searched StackOverflow for answers but apparently I couldn't find one to suit my situation.
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).
So, why the link doesn't work? Is it a Javascript problem or some other problem which I am not seeing?
Thanks.