Skip to content

Commit

Permalink
Exercise1: Styling HTML components with Bootstrap:
Browse files Browse the repository at this point in the history
* Change ul to dl in books#index
* Add classes to buttons
* Style the new/edit book form
* Style error messages
* Style flash messages
  • Loading branch information
Tair Assimov committed Mar 2, 2012
1 parent 1a16ace commit da89b28
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 37 deletions.
11 changes: 11 additions & 0 deletions app/helpers/application_helper.rb
@@ -1,2 +1,13 @@
module ApplicationHelper

def flash_class(name)
if name == :notice
"alert alert-success"
elsif name == :error
"alert alert-error"
else
"alert"
end
end

end
72 changes: 48 additions & 24 deletions app/views/books/_form.html.erb
@@ -1,29 +1,53 @@
<%= form_for @book do |f| %>
<%= form_for @book, html: { class: 'form-horizontal' } do |f| %>
<% unless @book.errors.empty? %>
<h2>Failed to save book</h2>
<% @book.errors.full_messages.each do |msg| %>
<p><%= msg %></p>
<% end %>
<div class='alert alert-block alert-error'>
<h2 class='alert-heading'>Failed to save book</h2>
<% @book.errors.full_messages.each do |msg| %>
<p><%= msg %></p>
<% end %>
</div>
<% end %>

<div>
Title:<br/>
<%= f.text_field :title %>
</div>
<div>
Authors:<br/>
<%= f.text_field :authors %>
</div>
<div>
ISBN:<br/>
<%= f.text_field :isbn %>
</div>
<div>
Description:<br/>
<%= f.text_area :description %>
</div>
<%= f.submit "Save" %>
or
<%= link_to "Cancel", books_path %>
<fieldset>
<div class='control-group'>
<label class='control-label' for="title">Title</label>
<div class='controls'>
<%= f.text_field :title %>
</div>
</fieldset>

<fieldset>
<div class='control-group'>
<label class='control-label' for="authors">Authors</label>
<div class='controls'>
<%= f.text_field :authors %>
</div>
</fieldset>

<fieldset>
<div class='control-group'>
<label class='control-label' for="isbn">ISBN</label>
<div class='controls'>
<%= f.text_field :isbn %>
</div>
</fieldset>

<fieldset>
<div class='control-group'>
<label class='control-label' for="description">Description</label>
<div class='controls'>
<%= f.text_field :description %>
</div>
</fieldset>

<fieldset>
<div class='controls'>
<%= f.submit "Save", class: 'btn-primary' %>
or
<%= link_to "Cancel", books_path %>
</div>
</fieldset>


<% end %>
14 changes: 6 additions & 8 deletions app/views/books/index.html.erb
@@ -1,6 +1,6 @@
<%= form_tag search_books_path, method: :get do %>
<%= text_field_tag :query, params[:query] || 'Search by title' %>
<%= submit_tag 'Search' %>
<%= submit_tag 'Search', class: 'btn-primary' %>
<div>
<%= query_by_radio_tag :title %>
<%= query_by_radio_tag :isbn %>
Expand All @@ -9,18 +9,16 @@
<% end %>

<p>
<%= link_to "Add a book", new_book_path %>
<%= link_to "Add a book", new_book_path, class: 'btn' %>
</p>

<% if @books.size > 0 %>
<ul>
<dl>
<% @books.each do |book| %>
<li>
<strong><%= link_to book.title, book_path(book) %></strong>
by <%= book.authors %>
</li>
<dt><%= link_to book.title, book_path(book) %></dt>
<dd><%= book.authors %></dd>
<% end %>
</ul>
</dl>
<% else %>
<h2>Sorry, we haven't found any books!</h2>
<% end %>
9 changes: 5 additions & 4 deletions app/views/books/show.html.erb
Expand Up @@ -18,15 +18,16 @@
<%= @book.description %>
</p>

<%= link_to "Edit", edit_book_path(@book) %>
<%= link_to "Delete", book_path, method: :delete %>
<%= link_to "Edit", edit_book_path(@book), class: 'btn' %>
<% if @book_reservation %>
<%= link_to "Free", free_book_reservation_path(@book, @book_reservation), method: :put %>
<%= link_to "Free", free_book_reservation_path(@book, @book_reservation), method: :put, class: 'btn' %>
<% else %>
<%= link_to "Reserve", new_book_reservation_path(@book) %>
<%= link_to "Reserve", new_book_reservation_path(@book), class: 'btn' %>
<% end %>
<%= link_to "Delete", book_path, method: :delete, class: 'btn btn-danger' %>

<p>
<%= link_to "Back to list", books_path %>
</p>
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Expand Up @@ -22,7 +22,7 @@
</div>

<% flash.each do |name,msg| %>
<div class="flash_<%=name%>">
<div class="<%= flash_class(name)%>">
<%= msg %>
</div>
<% end %>
Expand Down

0 comments on commit da89b28

Please sign in to comment.