Ruby on Rails Tutorial chapter 9.4 (add admin user) -
please error
error:
syntaxerror in userscontroller#index app/views/users/_user.html.erb:4: syntax error, unexpected ')', expecting keyword_then or ';' or '\n' ...dmin? && !current_user?(user) );@output_buffer.safe_append=' ... ^ app/views/users/_user.html.erb:7: syntax error, unexpected keyword_end '.freeze;@output_buffer.append=( end );@output_buffer.safe_append=' ^ /app/views/users/_user.html.erb:10: syntax error, unexpected keyword_ensure, expecting ')' /app/views/users/_user.html.erb:12: syntax error, unexpected keyword_end, expecting ')'
my /app/controllers/users_controller.rb
:
class userscontroller < applicationcontroller before_action :signed_in_user, only: [:index, :edit, :update, :destroy] before_action :correct_user, only: [:edit, :update] before_action :admin_user, only: :destroy def new @user = user.new end def index # @users = user.paginate(:page => params[:page]) @users = user.paginate(page: params[:page]) end def show @user = user.find(params[:id]) end def create @user = user.new(user_params) if @user.save sign_in @user flash[:success] = "welcome sample app!" redirect_to @user else render 'new' end end def edit # @user = user.find(params[:id]) end def update if @user.update_attributes(user_params) flash[:success] = "profile updated" redirect_to @user else render 'edit' end end def destroy user.find(params[:id]).destroy flash.now[:success] = "user deleted." redirect_to users_url end private def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end #before filters def signed_in_user redirect_to signin_url, notice: "please sign in." unless signed_in? end def correct_user @user = user.find(params[:id]) redirect_to(root_url) unless current_user?(@user) end def admin_user redirect_to(root_url) unless current_user.admin? end end
app/views/users/_user.html.erb
<li> <%= gravatar_for user, size: 52 %> <%= link_to user.name, user %> <%= if current_user.admin? && !current_user?(user) %> | <%= link_to 'delete', user, method: :delete, data: { confirm: "you sure?" } %> <%= end %> </li>
change app/views/users/_user.html.erb
code following:
<li> <%= gravatar_for user, size: 52 %> <%= link_to user.name, user %> <% if current_user.admin? && !current_user?(user) %> <%= link_to 'delete', user, method: :delete, data: { confirm: "you sure?" } %> <% end %> </li>
Comments
Post a Comment