ruby on rails - Syntax to allow admin to see all pages -


i want display page if page public. if user of page trying view page if it's private , if it's admin trying view page.

i have written

 <% if @user.is_public == true || session[:user_id] ==  @user.id %>  <%= render "public_page" %>  <% else %>  private page  <%end%> 

i don't know how add below mix. ideas?

<% unless session[:site_admin] %> 

the purpose allow site admin view private pages.

just add check if:

<% if @user.is_public == true || session[:user_id] ==  @user.id || session[:site_admin] %>   <%= render "public_page" %> <% else %>   private page <%end%> 

btw, more ruby way of naming is_public method public?

btw btw, if project big , want solid permission management it's practice use devise gem combined cancancan. define permissions in single place, models/ability.rb , check permissions can? :read, @post.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -