-
-
Save febuiles/31392 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| class FooController | |
| def destroy | |
| editable_by :admin | |
| puts "OH HAI" | |
| end | |
| end | |
| class ApplicationController < ActionController::Base | |
| private | |
| def editable_by(role) | |
| if current_user.role < role_with_symbol(role) | |
| flash[:error] = "GTFO DOOD" | |
| redirect_to "/" | |
| end | |
| end | |
| def role_with_symbol(sym) | |
| case sym | |
| when :admin then 5 | |
| when :colab then 4 | |
| when :batman then 3.141592 | |
| else 0 | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment