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!"
|
redirect_to new_session_url, alert: "Please sign in first!"
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
class MoviesController < ApplicationController
|
class MoviesController < ApplicationController
|
||||||
|
before_action :require_admin, except: [:index, :show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@movies = Movie.released
|
@movies = Movie.released
|
||||||
end
|
end
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
<section class="admin">
|
<section class="admin">
|
||||||
|
<% if current_user_admin? %>
|
||||||
<%= link_to "Add New Movie", new_movie_path, class: "button" %>
|
<%= link_to "Add New Movie", new_movie_path, class: "button" %>
|
||||||
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,8 +30,10 @@
|
|||||||
</table>
|
</table>
|
||||||
<%= link_to "Write Review", new_movie_review_path(@movie), class: "review" %>
|
<%= link_to "Write Review", new_movie_review_path(@movie), class: "review" %>
|
||||||
<section class="admin">
|
<section class="admin">
|
||||||
|
<% if current_user_admin? %>
|
||||||
<%= link_to "Edit", edit_movie_path(@movie), class: "button" %>
|
<%= 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?" } %>
|
<%= link_to "Delete", movie_path(@movie), class: "button", data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %>
|
||||||
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user