Skip to content

Commit

Permalink
ruby 1.9 comp
Browse files Browse the repository at this point in the history
  • Loading branch information
jastix committed Jun 29, 2009
1 parent 624bb41 commit fe1719b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/controllers/reviews_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
class ReviewsController < ApplicationController
def index
@reviews = Review.all

end

def list
@reviews = Review.all
#@reviews = Review.search(params[:search])
#render :action => 'list', :layout => false
end

def show
@review = Review.find(params[:id])
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@ class Review < ActiveRecord::Base
validates_numericality_of :rating, :only_integer => true
validates_inclusion_of :rating, :in => 1..10

def self.search(search)
if search.empty
find(:all, :conditions => {:book_id => search})
else
find(:all)
end
end
end

2 changes: 1 addition & 1 deletion app/views/books/_book.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<td><%=h book.published_year %></td>
<td><%=h book.genres.map {|genre| genre.name}.compact.join(' , ') %></td>
<td><%=h book.isbn %></td>
<td><%=h truncate(book.description.to_s, 30) %></td>
<td><%=h book.description.to_s[0..30] %></td>
<td><%= link_to book.user.login, user_path(book.user_id) %></td>
<td><%= book.readers.length %></td>
<td><%= link_to "Show", book %></td>
Expand Down
7 changes: 7 additions & 0 deletions app/views/books/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
<strong>Isbn:</strong>
<%=h @book.isbn %>
</p>

<p>
<strong>Description:</strong>
<%=h @book.description %>
</p>
<p>
<strong>Description:</strong>

<%= link_to @book.reviews.length.to_s, reviews_path(:search => @book.id, :target => '_blank', :layout => false) %>
</p>
<p class="added_by">
<strong>Added by:</strong>
<span><%= link_to @book.user.login, user_path(@book.user_id) %></span>
<% if logged_in? %>

<% if @book.user != @current_user && !@current_user.friends.include?(@book.user)%>
<%= link_to 'Add friend', friendships_path(:friend_id => @book.user_id), :method => :post %>
<% end %>
Expand Down
20 changes: 20 additions & 0 deletions app/views/reviews/list.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h2> Reviews </h2>

<table>
<tr>
<th>Book</th>
<th>User</th>
<th>Review</th>
<th>Rating</th>
</tr>
<% for review in @reviews %>
<tr>
<td><%=h review.book.title %></td>
<td><%=h review.user.name %></td>
<td><%=h review.review %></td>
<td><%=h review.rating %></td>

</tr>
<% end %>
</table>

2 changes: 1 addition & 1 deletion app/views/users/_books.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<td><%=h book.published_year %></td>
<td><%=h book.genres.map {|genre| genre.name}.compact.join(' , ') %></td>
<td><%=h book.isbn %></td>
<td><%=h truncate (book.description, 30) %></td>
<td><%=h book.description.to_s[0..30] %></td>
</tr>
<% end %>

Expand Down

0 comments on commit fe1719b

Please sign in to comment.