-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jastix
committed
Jun 28, 2009
1 parent
0b16de2
commit 69d1b28
Showing
26 changed files
with
383 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ def create | |
|
||
else | ||
wants.html { render :action => 'new' } | ||
|
||
wants.js | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
class ReviewsController < ApplicationController | ||
def index | ||
@reviews = Review.all | ||
end | ||
|
||
def show | ||
@review = Review.find(params[:id]) | ||
end | ||
|
||
def new | ||
@review = Review.new(:book_id => params[:book_id]) | ||
|
||
|
||
respond_to do |wants| | ||
wants.html | ||
|
||
end | ||
|
||
end | ||
|
||
def create | ||
params[:review][:user_id] = @current_user.id | ||
@review = Review.new(params[:review]) | ||
|
||
respond_to do |wants| | ||
if @review.save | ||
wants.html do | ||
flash[:notice] = "Successfully created review." | ||
redirect_to @review | ||
end | ||
|
||
else | ||
wants.html { render :action => 'new' } | ||
|
||
end | ||
end | ||
end | ||
|
||
def edit | ||
@review = Review.find(params[:id]) | ||
respond_to do |wants| | ||
wants.html | ||
|
||
end | ||
|
||
end | ||
|
||
def update | ||
|
||
@review = Review.find(params[:id]) | ||
params[:review][:user_id] = @current_user.id | ||
respond_to do |wants| | ||
if @review.update_attributes(params[:review]) | ||
wants.html do | ||
flash[:notice] = "Successfully updated review." | ||
redirect_to @review | ||
end | ||
|
||
else | ||
wants.html { render :action => 'edit' } | ||
|
||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@review = Review.find(params[:id]) | ||
@review.destroy | ||
flash[:notice] = "Successfully removed review." | ||
redirect_to reviews_url | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ReviewsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Review < ActiveRecord::Base | ||
|
||
belongs_to :book | ||
belongs_to :user | ||
|
||
validates_presence_of :review, :rating, :book_id, :user_id | ||
#attr_accessible :book_id, :review, :rating, :user_id | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<% form_for @review do |f| %> | ||
<%= f.error_messages %> | ||
<%= f.hidden_field :book_id, :value => @review.book_id%> | ||
<p> | ||
<%= f.label :review %><br /> | ||
<%= f.text_area :review %> | ||
</p> | ||
|
||
<p> | ||
<%= f.label :rating %><br /> | ||
<%= f.text_field :rating %> | ||
</p> | ||
<p><%= f.submit "Submit" %></p> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h2> Edit Review </h2> | ||
|
||
<%= render :partial => 'form' %> | ||
|
||
<p> | ||
<%= link_to "Show", @review %> | | ||
<%= link_to "View All", reviews_path %> | ||
</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<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> | ||
<td><%= link_to "Show", review %></td> | ||
<% if logged_in? %> | ||
<% if @current_user == review.user.id %> | ||
<td><%= link_to "Edit", edit_review_path(review) %></td> | ||
<td><%= link_to "Destroy", review, :confirm => 'Are you sure?', :method => :delete %></td> | ||
<% end %> | ||
<% end %> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h2> New Review </h2> | ||
|
||
<%= render :partial => 'form' %> | ||
|
||
<p><%= link_to "Back to List", reviews_path %></p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<h2> Review </h2> | ||
|
||
|
||
<p> | ||
<strong>Review:</strong> | ||
<%=h @review.review %> | ||
</p> | ||
<p> | ||
<strong>Rating:</strong> | ||
<%=h @review.rating %> | ||
</p> | ||
<p> | ||
<strong>Book:</strong> | ||
<%=h @review.book.title %> | ||
</p> | ||
<p> | ||
<strong>User:</strong> | ||
<%=h @review.user.name %> | ||
</p> | ||
<p> | ||
|
||
<%= link_to "Edit", edit_review_path(@review) %> | | ||
<%= link_to "Destroy", @review, :confirm => 'Are you sure?', :method => :delete %> | | ||
<%= link_to "View All", reviews_path %> | ||
</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.