Last active
August 29, 2015 14:05
-
-
Save mahm/03c8555bb573948c6735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# members_controller.rb | |
class MembersController < ApplicationController | |
def destroy | |
if !checkadmin? then return end | |
@member = Member.find(params[:id]) | |
@member.destroy | |
respond_to do |format| | |
format.html { redirect_to members_url } | |
format.json { head :no_content } | |
end | |
end | |
end | |
# application_controller.rb | |
class ApplicationController < ActionController::Base | |
def checkadmin? | |
if session[:login].admin then | |
return true | |
else | |
redirect_to '/members/' + session[:login].id.to_s | |
return false | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# members_controller.rb | |
class MembersController < ApplicationController | |
before_action :redirect_to_member_page, unless: -> { current_member.admin? }, only: %i(destroy) | |
def destroy | |
@member = Member.find(params[:id]) | |
@member.destroy | |
respond_to do |format| | |
format.html { redirect_to members_url } | |
format.json { head :no_content } | |
end | |
end | |
end | |
# application_controller.rb | |
class ApplicationController < ActionController::Base | |
helper_method :current_member | |
private | |
def current_member | |
@current_member ||= Member.find_by(id: session[:member_id]) | |
end | |
def redirect_to_member_page | |
redirect_to member_url(current_member.id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment