Complete Lesson 34
This commit is contained in:
parent
32fd91bb5c
commit
f9a7010911
@ -15,4 +15,15 @@ class ApplicationController < ActionController::Base
|
||||
redirect_to new_session_url, alert: "Please sign in first!"
|
||||
end
|
||||
end
|
||||
|
||||
def current_user_admin?
|
||||
current_user && current_user.admin?
|
||||
end
|
||||
helper_method :current_user_admin?
|
||||
|
||||
def require_admin
|
||||
unless current_user_admin?
|
||||
redirect_to root_url, alert: "Unauthorized access!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,6 @@
|
||||
class MoviesController < ApplicationController
|
||||
before_action :require_admin, except: [:index, :show]
|
||||
|
||||
def index
|
||||
@movies = Movie.released
|
||||
end
|
||||
|
@ -23,6 +23,8 @@
|
||||
<% end %>
|
||||
</ul>
|
||||
<section class="admin">
|
||||
<% if current_user_admin? %>
|
||||
<%= link_to "Add New Movie", new_movie_path, class: "button" %>
|
||||
<% end %>
|
||||
</section>
|
||||
</div>
|
||||
|
@ -30,8 +30,10 @@
|
||||
</table>
|
||||
<%= link_to "Write Review", new_movie_review_path(@movie), class: "review" %>
|
||||
<section class="admin">
|
||||
<% if current_user_admin? %>
|
||||
<%= link_to "Edit", edit_movie_path(@movie), class: "button" %>
|
||||
<%= link_to "Delete", movie_path(@movie), class: "button", data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %>
|
||||
<% end %>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
|
Loading…
x
Reference in New Issue
Block a user