books edition by admin
This commit is contained in:
parent
5095f63fd7
commit
e36cc36947
10 changed files with 119 additions and 20 deletions
14
app/views/books/edit.html.erb
Normal file
14
app/views/books/edit.html.erb
Normal file
|
@ -0,0 +1,14 @@
|
|||
<h4>Edit book</h4>
|
||||
<%= form_for @book do |f|%>
|
||||
<%= f.label :title %>
|
||||
<%= f.text_field :title %>
|
||||
<%= f.label :price %>
|
||||
<%= f.number_field :price, step: 0.01 %>
|
||||
<label>
|
||||
<div>
|
||||
<%= f.check_box :published, class: 'filled-in' %>
|
||||
<span>published</span>
|
||||
</div>
|
||||
</label>
|
||||
<%= f.submit 'Save changes', class: 'btn' %>
|
||||
<%end%>
|
|
@ -1,17 +1,27 @@
|
|||
<div class='container'>
|
||||
<% @books.each do |book| %>
|
||||
<div class='row'>
|
||||
<div class='col s4'>
|
||||
Title: <%= book.title %>
|
||||
<div class='col s3'>
|
||||
Title: <%= link_to book.title, book %>
|
||||
</div>
|
||||
|
||||
<div class='col s4'>
|
||||
Price: <%= book.price %>
|
||||
<div class='col s3'>
|
||||
Price: <%= book.price_with_currency %>
|
||||
</div>
|
||||
|
||||
<div class='col s4'>
|
||||
<div class='col s3'>
|
||||
Authors: <%= book.authors %>
|
||||
|
||||
</div>
|
||||
|
||||
<% if current_user.admin? %>
|
||||
<div class='col s2'>
|
||||
<%= book.published ? 'published' : 'unpublished' %>
|
||||
</div>
|
||||
<div class='col s1'>
|
||||
<%= link_to 'Edit', edit_book_path(book), class: "btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
20
app/views/books/show.html.erb
Normal file
20
app/views/books/show.html.erb
Normal file
|
@ -0,0 +1,20 @@
|
|||
<div class='container'>
|
||||
<div class='row'>
|
||||
<div class='col s4'>
|
||||
Title: <%= link_to @book.title, @book %>
|
||||
</div>
|
||||
|
||||
<div class='col s4'>
|
||||
Price: <%= @book.price_with_currency %>
|
||||
</div>
|
||||
|
||||
<div class='col s4'>
|
||||
Authors: <%= @book.authors %>
|
||||
</div>
|
||||
</div>
|
||||
<% if current_user&.admin? %>
|
||||
<div class='row'>
|
||||
<%= link_to 'Edit', edit_book_path(@book), class: "btn" %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
<body>
|
||||
<%= link_to 'Home', '/welcome', method: :get%>
|
||||
<%= link_to 'Books', '/books', method: :get%>
|
||||
<% flash.each do |type, notice| %>
|
||||
<div class='card-panel teal lighten-5'>
|
||||
<% if notice.is_a? String %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue