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
Showing
6 changed files
with
237 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
// Place all the styles related to the photos controller here. | ||
// Place all the styles related to the Photos controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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 |
---|---|---|
@@ -1,5 +1,83 @@ | ||
class PhotosController < ApplicationController | ||
# GET /photos | ||
# GET /photos.json | ||
def index | ||
@photos = Photo.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render :json => @photos } | ||
end | ||
end | ||
|
||
# GET /photos/1 | ||
# GET /photos/1.json | ||
def show | ||
@photo = Photo.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render :json => @photo } | ||
end | ||
end | ||
|
||
# GET /photos/new | ||
# GET /photos/new.json | ||
def new | ||
@photo = Photo.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render :json => @photo } | ||
end | ||
end | ||
|
||
# GET /photos/1/edit | ||
def edit | ||
@photo = Photo.find(params[:id]) | ||
end | ||
|
||
# POST /photos | ||
# POST /photos.json | ||
def create | ||
@photo = Photo.new(params[:photo]) | ||
|
||
respond_to do |format| | ||
if @photo.save | ||
format.html { redirect_to @photo, :notice => 'Photo was successfully created.' } | ||
format.json { render :json => @photo, :status => :created, :location => @photo } | ||
else | ||
format.html { render :action => "new" } | ||
format.json { render :json => @photo.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /photos/1 | ||
# PUT /photos/1.json | ||
def update | ||
@photo = Photo.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @photo.update_attributes(params[:photo]) | ||
format.html { redirect_to @photo, :notice => 'Photo was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render :action => "edit" } | ||
format.json { render :json => @photo.errors, :status => :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /photos/1 | ||
# DELETE /photos/1.json | ||
def destroy | ||
@photo = Photo.find(params[:id]) | ||
@photo.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to photos_url } | ||
format.json { head :no_content } | ||
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 |
---|---|---|
@@ -1 +1,25 @@ | ||
hello | ||
<h1>Listing photos</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Title</th> | ||
<th>Name</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @photos.each do |photo| %> | ||
<tr> | ||
<td><%= photo.title %></td> | ||
<td><%= photo.name %></td> | ||
<td><%= link_to 'Show', photo %></td> | ||
<td><%= link_to 'Edit', edit_photo_path(photo) %></td> | ||
<td><%= link_to 'Destroy', photo, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Photo', new_photo_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 | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,49 @@ | ||
require 'test_helper' | ||
|
||
class PhotosControllerTest < ActionController::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
setup do | ||
@photo = photos(:one) | ||
end | ||
|
||
test "should get index" do | ||
get :index | ||
assert_response :success | ||
assert_not_nil assigns(:photos) | ||
end | ||
|
||
test "should get new" do | ||
get :new | ||
assert_response :success | ||
end | ||
|
||
test "should create photo" do | ||
assert_difference('Photo.count') do | ||
post :create, :photo => { :name => @photo.name, :title => @photo.title } | ||
end | ||
|
||
assert_redirected_to photo_path(assigns(:photo)) | ||
end | ||
|
||
test "should show photo" do | ||
get :show, :id => @photo | ||
assert_response :success | ||
end | ||
|
||
test "should get edit" do | ||
get :edit, :id => @photo | ||
assert_response :success | ||
end | ||
|
||
test "should update photo" do | ||
put :update, :id => @photo, :photo => { :name => @photo.name, :title => @photo.title } | ||
assert_redirected_to photo_path(assigns(:photo)) | ||
end | ||
|
||
test "should destroy photo" do | ||
assert_difference('Photo.count', -1) do | ||
delete :destroy, :id => @photo | ||
end | ||
|
||
assert_redirected_to photos_path | ||
end | ||
end |