Access restrictions for users who are not logged in Access restrictions for logged-in users Description in view file
Write before_action
in the controller
***controller.rb
before_action :forbid_login_user, {only: [:top]}
#~Other descriptions are omitted~
def autheniticate_user
if @current_user.nil?
flash[:notice]="Please login"
redirect_to("/URL")
end
end
Write before_action
in the controller
***controller.rb
before_action :forbid_login_user, {only: [:top]}
#~Other descriptions are omitted~
def fobid_login_user
if @current_user
flash[:notice]="You are logged in"
redirect_to("/URL")
end
end
Suppose you are using devise
.
***.html.erb
<% if user_signed_in? && current_user.id == @usesinfo.usersid %>
<li>
<%= link_to 'edit', "/URL", method: :get %>
</li>
<li>
<%= link_to 'delete', "/URL", method: :delete %>
</li>
<% end %>
Recommended Posts