Skip to content

Instantly share code, notes, and snippets.

@fresh5447
Created May 5, 2014 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fresh5447/9daed3027c8d13893217 to your computer and use it in GitHub Desktop.
Save fresh5447/9daed3027c8d13893217 to your computer and use it in GitHub Desktop.
Wiki Index View
<h1>My wikis</h1>
<div class="row">
<% if policy(Wiki.new).create? %> <%#added policy instead of if user %>
<%= link_to 'New', new_wiki_path, class: 'btn btn-primary btn-large' %>
<% end %>
<% if current_user.role?("free") %>
<h2><%= link_to "Upgrade Account", new_charge_path, class: 'btn btn-primary btn-large' %></h2>
</div>
<% end %>
<table class="table table-bordered">
<thead>
<tr class="info">
<th>User</th>
<th>Name</th>
<th>Body</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% policy_scope(@user.wikis).each do |wiki| %>
<tr class="active">
<td><%= wiki.user.name if wiki.user %></td>
<td><%= wiki.name %></td>
<td><%= wiki.body %></td>
<td><%= link_to 'Show', wiki %> |
<% if policy(wiki).edit? %>
<%= link_to 'Edit', edit_wiki_path(wiki) %>
<% end %> |
<% if policy(wiki).destroy? %>
<%= link_to 'Destroy', wiki, method: :delete, data: { confirm: 'Are you sure?' } %>
<% end %>
<% if current_user.role?("premium") %>
<%= link_to 'Add Collaborators', new_wiki_collaborator_path(wiki) %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment