Note that there are some explanatory texts on larger screens.

plurals
  1. POWorking on railstutorial.org Ch 10. Cannot delete users through browser as admin
    primarykey
    data
    text
    <p>In chapter 10 of railstutorial.org, I cannot delete users through the browser. All tests pass, including user deletion tests, but when attempting to delete a user as an admin through the browser pointed to localhost:3000, I am merely directed to the user's profile.</p> <pre><code>&lt;%= link_to "delete", user, :method =&gt; :delete, :confirm =&gt; "Are you sure?", :title =&gt; "Delete #{user.name}" %&gt; </code></pre> <p>Is the code used to generate the deletion link.</p> <pre><code>&lt;%= javascript_include_tag :defaults %&gt; </code></pre> <p>has been included in the headers.</p> <p>I'm really stumped as to why this is happening. The logs for the server show a GET request for the user's info, as one would expect when being directed to the user page rather than destroying the user.</p> <p>Also, using <code>button_to</code> instead of <code>link_to</code> will delete a user, but won't confirm the action.</p> <p>EDIT: Adding routes.rb by request</p> <pre><code>resources :sessions, :only =&gt; [:new, :create, :destroy] resources :users match '/contact', :to =&gt; 'pages#contact' match '/about', :to =&gt; 'pages#about' match '/help', :to =&gt; 'pages#help' match '/signup', :to =&gt; 'users#new' match '/signin', :to =&gt; 'sessions#new' match '/signout', :to =&gt; 'sessions#destroy' root :to =&gt; 'pages#home' get "pages/home" get "pages/contact" get "pages/about" get "pages/help" </code></pre> <p>EDIT: application.js added by request</p> <pre><code>require jquery require jquery_ujs require_tree . </code></pre> <p>EDIT: users_controller.rb added by request</p> <pre><code>class UsersController &lt; ApplicationController before_filter :authenticate, :only =&gt; [:index, :edit, :update, :destroy] before_filter :correct_user, :only =&gt; [:edit, :update] before_filter :admin_user, :only =&gt; :destroy def show @user = User.find(params[:id]) @title = @user.name end def new @user = User.new @title = "Sign Up" end def create @user = User.new(params[:user]) UserMailer.pw_email(@user).deliver if @user.save sign_in @user flash[:success] = "Welcome to Sample App!" redirect_to @user else @title = "Sign Up" render 'new' end end def edit @title = "Edit User" end def update if @user.update_attributes(params[:user]) flash[:success] = "Profile Updated" redirect_to @user else @title = "Edit User" render 'edit' end end def index @title = "All Users" @users = User.paginate(:page =&gt; params[:page]) end def show @user = User.find(params[:id]) @title = @user.name end def destroy User.find(params[:id]).destroy flash[:success] = "User destroyed" redirect_to users_path end private def authenticate deny_access unless signed_in? end def correct_user @user = User.find(params[:id]) redirect_to(root_path) unless current_user?(@user) end def admin_user redirect_to(root_path) unless current_user.admin? end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload