Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
38 changed files
with
1,150 additions
and
0 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,85 @@ | |||
class CommentsController < ApplicationController | |||
# GET /comments | |||
# GET /comments.xml | |||
def index | |||
@comments = Comment.find(:all) | |||
|
|||
respond_to do |format| | |||
format.html # index.html.erb | |||
format.xml { render :xml => @comments } | |||
end | |||
end | |||
|
|||
# GET /comments/1 | |||
# GET /comments/1.xml | |||
def show | |||
@comment = Comment.find(params[:id]) | |||
|
|||
respond_to do |format| | |||
format.html # show.html.erb | |||
format.xml { render :xml => @comment } | |||
end | |||
end | |||
|
|||
# GET /comments/new | |||
# GET /comments/new.xml | |||
def new | |||
@comment = Comment.new | |||
|
|||
respond_to do |format| | |||
format.html # new.html.erb | |||
format.xml { render :xml => @comment } | |||
end | |||
end | |||
|
|||
# GET /comments/1/edit | |||
def edit | |||
@comment = Comment.find(params[:id]) | |||
end | |||
|
|||
# POST /comments | |||
# POST /comments.xml | |||
def create | |||
@comment = Comment.new(params[:comment]) | |||
|
|||
respond_to do |format| | |||
if @comment.save | |||
flash[:notice] = 'Comment was successfully created.' | |||
format.html { redirect_to(@comment) } | |||
format.xml { render :xml => @comment, :status => :created, :location => @comment } | |||
else | |||
format.html { render :action => "new" } | |||
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity } | |||
end | |||
end | |||
end | |||
|
|||
# PUT /comments/1 | |||
# PUT /comments/1.xml | |||
def update | |||
@comment = Comment.find(params[:id]) | |||
|
|||
respond_to do |format| | |||
if @comment.update_attributes(params[:comment]) | |||
flash[:notice] = 'Comment was successfully updated.' | |||
format.html { redirect_to(@comment) } | |||
format.xml { head :ok } | |||
else | |||
format.html { render :action => "edit" } | |||
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity } | |||
end | |||
end | |||
end | |||
|
|||
# DELETE /comments/1 | |||
# DELETE /comments/1.xml | |||
def destroy | |||
@comment = Comment.find(params[:id]) | |||
@comment.destroy | |||
|
|||
respond_to do |format| | |||
format.html { redirect_to(comments_url) } | |||
format.xml { head :ok } | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,85 @@ | |||
class ProductsController < ApplicationController | |||
# GET /products | |||
# GET /products.xml | |||
def index | |||
@products = Product.find(:all) | |||
|
|||
respond_to do |format| | |||
format.html # index.html.erb | |||
format.xml { render :xml => @products } | |||
end | |||
end | |||
|
|||
# GET /products/1 | |||
# GET /products/1.xml | |||
def show | |||
@product = Product.find(params[:id]) | |||
|
|||
respond_to do |format| | |||
format.html # show.html.erb | |||
format.xml { render :xml => @product } | |||
end | |||
end | |||
|
|||
# GET /products/new | |||
# GET /products/new.xml | |||
def new | |||
@product = Product.new | |||
|
|||
respond_to do |format| | |||
format.html # new.html.erb | |||
format.xml { render :xml => @product } | |||
end | |||
end | |||
|
|||
# GET /products/1/edit | |||
def edit | |||
@product = Product.find(params[:id]) | |||
end | |||
|
|||
# POST /products | |||
# POST /products.xml | |||
def create | |||
@product = Product.new(params[:product]) | |||
|
|||
respond_to do |format| | |||
if @product.save | |||
flash[:notice] = 'Product was successfully created.' | |||
format.html { redirect_to(@product) } | |||
format.xml { render :xml => @product, :status => :created, :location => @product } | |||
else | |||
format.html { render :action => "new" } | |||
format.xml { render :xml => @product.errors, :status => :unprocessable_entity } | |||
end | |||
end | |||
end | |||
|
|||
# PUT /products/1 | |||
# PUT /products/1.xml | |||
def update | |||
@product = Product.find(params[:id]) | |||
|
|||
respond_to do |format| | |||
if @product.update_attributes(params[:product]) | |||
flash[:notice] = 'Product was successfully updated.' | |||
format.html { redirect_to(@product) } | |||
format.xml { head :ok } | |||
else | |||
format.html { render :action => "edit" } | |||
format.xml { render :xml => @product.errors, :status => :unprocessable_entity } | |||
end | |||
end | |||
end | |||
|
|||
# DELETE /products/1 | |||
# DELETE /products/1.xml | |||
def destroy | |||
@product = Product.find(params[:id]) | |||
@product.destroy | |||
|
|||
respond_to do |format| | |||
format.html { redirect_to(products_url) } | |||
format.xml { head :ok } | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module CommentsHelper | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
module ProductsHelper | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
class Comment < ActiveRecord::Base | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
class Product < ActiveRecord::Base | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
<h1>Editing comment</h1> | |||
|
|||
<% form_for(@comment) do |f| %> | |||
<%= f.error_messages %> | |||
|
|||
<p> | |||
<%= f.label :name %><br /> | |||
<%= f.text_field :name %> | |||
</p> | |||
<p> | |||
<%= f.label :body %><br /> | |||
<%= f.text_area :body %> | |||
</p> | |||
<p> | |||
<%= f.submit "Update" %> | |||
</p> | |||
<% end %> | |||
<%= link_to 'Show', @comment %> | | |||
<%= link_to 'Back', comments_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
<h1>Listing comments</h1> | |||
|
|||
<table> | |||
<tr> | |||
<th>Name</th> | |||
<th>Body</th> | |||
</tr> | |||
|
|||
<% for comment in @comments %> | |||
<tr> | |||
<td><%=h comment.name %></td> | |||
<td><%=h comment.body %></td> | |||
<td><%= link_to 'Show', comment %></td> | |||
<td><%= link_to 'Edit', edit_comment_path(comment) %></td> | |||
<td><%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete %></td> | |||
</tr> | |||
<% end %> | |||
</table> | |||
|
|||
<br /> | |||
|
|||
<%= link_to 'New comment', new_comment_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
<h1>New comment</h1> | |||
|
|||
<% form_for(@comment) do |f| %> | |||
<%= f.error_messages %> | |||
|
|||
<p> | |||
<%= f.label :name %><br /> | |||
<%= f.text_field :name %> | |||
</p> | |||
<p> | |||
<%= f.label :body %><br /> | |||
<%= f.text_area :body %> | |||
</p> | |||
<p> | |||
<%= f.submit "Create" %> | |||
</p> | |||
<% end %> | |||
<%= link_to 'Back', comments_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
<p> | |||
<b>Name:</b> | |||
<%=h @comment.name %> | |||
</p> | |||
|
|||
<p> | |||
<b>Body:</b> | |||
<%=h @comment.body %> | |||
</p> | |||
|
|||
|
|||
<%= link_to 'Edit', edit_comment_path(@comment) %> | | |||
<%= link_to 'Back', comments_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
<h1>Editing product</h1> | |||
|
|||
<% form_for(@product) do |f| %> | |||
<%= f.error_messages %> | |||
|
|||
<p> | |||
<%= f.label :name %><br /> | |||
<%= f.text_field :name %> | |||
</p> | |||
<p> | |||
<%= f.label :price %><br /> | |||
<%= f.text_field :price %> | |||
</p> | |||
<p> | |||
<%= f.submit "Update" %> | |||
</p> | |||
<% end %> | |||
<%= link_to 'Show', @product %> | | |||
<%= link_to 'Back', products_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
<h1>Listing products</h1> | |||
|
|||
<table> | |||
<tr> | |||
<th>Name</th> | |||
<th>Price</th> | |||
</tr> | |||
|
|||
<% for product in @products %> | |||
<tr> | |||
<td><%=h product.name %></td> | |||
<td><%=h product.price %></td> | |||
<td><%= link_to 'Show', product %></td> | |||
<td><%= link_to 'Edit', edit_product_path(product) %></td> | |||
<td><%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method => :delete %></td> | |||
</tr> | |||
<% end %> | |||
</table> | |||
|
|||
<br /> | |||
|
|||
<%= link_to 'New product', new_product_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
<h1>New product</h1> | |||
|
|||
<% form_for(@product) do |f| %> | |||
<%= f.error_messages %> | |||
|
|||
<p> | |||
<%= f.label :name %><br /> | |||
<%= f.text_field :name %> | |||
</p> | |||
<p> | |||
<%= f.label :price %><br /> | |||
<%= f.text_field :price %> | |||
</p> | |||
<p> | |||
<%= f.submit "Create" %> | |||
</p> | |||
<% end %> | |||
<%= link_to 'Back', products_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
<p> | |||
<b>Name:</b> | |||
<%=h @product.name %> | |||
</p> | |||
|
|||
<p> | |||
<b>Price:</b> | |||
<%=h @product.price %> | |||
</p> | |||
|
|||
|
|||
<%= link_to 'Edit', edit_product_path(@product) %> | | |||
<%= link_to 'Back', products_path %> |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
class CreateProducts < ActiveRecord::Migration | |||
def self.up | |||
create_table :products do |t| | |||
t.string :name | |||
t.decimal :price, :precision => 12, :scale => 2 | |||
|
|||
t.timestamps | |||
end | |||
end | |||
|
|||
def self.down | |||
drop_table :products | |||
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
class CreateComments < ActiveRecord::Migration | |||
def self.up | |||
create_table :comments do |t| | |||
t.string :name | |||
t.text :body | |||
|
|||
t.timestamps | |||
end | |||
end | |||
|
|||
def self.down | |||
drop_table :comments | |||
end | |||
end |
Oops, something went wrong.