views for album. controlling
This commit is contained in:
parent
a60a9d56f9
commit
b7eb8027dc
10 changed files with 129 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
class AlbumsController < ApplicationController
|
||||
before_filter :require_user, :only => [:new, :create, :edit, :update, :delete, :destroy]
|
||||
|
||||
def index
|
||||
@albums = Album.find(:all)
|
||||
|
@ -17,5 +18,44 @@ class AlbumsController < ApplicationController
|
|||
format.xml { render :xml => @album }
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@album = Album.new
|
||||
end
|
||||
|
||||
def create
|
||||
@album = Album.new(params[:album])
|
||||
if @album.save
|
||||
Dir.mkdir( APP_CONFIG[:photos_path] + @album.title )
|
||||
Dir.mkdir( APP_CONFIG[:thumbs_path] + @album.title )
|
||||
flash[:notice] = "Album created!"
|
||||
redirect_to @album
|
||||
else
|
||||
render :action => :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@album = Album.find( params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@album = Album.find( params[:id])
|
||||
if @album.update_attributes(params[:album])
|
||||
flash[:notice] = "Account updated!"
|
||||
redirect_to @album
|
||||
else
|
||||
render :action => :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destory
|
||||
@album = Album.find( params[:id])
|
||||
if @album.destory
|
||||
redirect_to album_path
|
||||
else
|
||||
redirect_to @album
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
filter_parameter_logging :password, :password_confirmation
|
||||
helper_method :current_user, :current_user_session
|
||||
|
||||
|
||||
private
|
||||
def current_user_session
|
||||
return @current_user_session if defined?(@current_user_session)
|
||||
|
|
|
@ -1,2 +1,59 @@
|
|||
class PhotosController < ApplicationController
|
||||
before_filter :require_user, :only => [:new, :create, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@photos = Photo.find(:all)
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render :json => @photos }
|
||||
format.xml { render :xml => @photos }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@photo = Photo.find( params[:id])
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render :json => @photo }
|
||||
format.xml { render :xml => @photo }
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@photo = Photo.new
|
||||
end
|
||||
|
||||
def create
|
||||
@photo = Photo.new(params[:photo])
|
||||
if @photo.save
|
||||
# upload
|
||||
flash[:notice] = "Photo created!"
|
||||
redirect_to @photo
|
||||
else
|
||||
render :action => :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@photo = Photo.find( params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@photo = Photo.find( params[:id])
|
||||
if @photo.update_attributes(params[:photo])
|
||||
flash[:notice] = "Account updated!"
|
||||
redirect_to @photo
|
||||
else
|
||||
render :action => :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destory
|
||||
@photo = Photo.find( params[:id])
|
||||
if @photo.destory
|
||||
redirect_to photo_path
|
||||
else
|
||||
redirect_to @photo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
class Album < ActiveRecord::Base
|
||||
has_many :photos
|
||||
|
||||
validates_uniqueness_of :path, :message => "Album already exsists on disc"
|
||||
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
class Photo < ActiveRecord::Base
|
||||
belongs_to :album
|
||||
|
||||
validates_uniqueness_of :path, :message => "Photo already exsists on disc"
|
||||
end
|
||||
|
|
4
app/views/albums/_form.html.erb
Normal file
4
app/views/albums/_form.html.erb
Normal file
|
@ -0,0 +1,4 @@
|
|||
<%= form.label :title %><br />
|
||||
<%= form.text_field :title %><br />
|
||||
<br />
|
||||
<%= @album.path %>
|
9
app/views/albums/edit.html.erb
Normal file
9
app/views/albums/edit.html.erb
Normal file
|
@ -0,0 +1,9 @@
|
|||
<h1>Edit Album</h1>
|
||||
|
||||
<% form_for @album do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= render :partial => "form", :object => f %>
|
||||
<%= f.submit "Update" %>
|
||||
<% end %>
|
||||
|
||||
<br /><%= link_to "All albums", albums_path %>
|
9
app/views/albums/new.html.erb
Normal file
9
app/views/albums/new.html.erb
Normal file
|
@ -0,0 +1,9 @@
|
|||
<h1>New Album</h1>
|
||||
|
||||
<% form_for @album do |f| %>
|
||||
<%= f.error_messages %>
|
||||
<%= render :partial => "form", :object => f %>
|
||||
<%= f.submit "Create" %>
|
||||
<% end %>
|
||||
|
||||
<br /><%= link_to "All albums", albums_path %>
|
|
@ -32,6 +32,9 @@ $('#photos').galleryView({
|
|||
|
||||
-->
|
||||
|
||||
<% if current_user %>
|
||||
<%= link_to "Edit album", edit_album_path( @album )%>
|
||||
<% end %>
|
||||
<link href="/javascripts/galleria/galleria.css" rel="stylesheet" type="text/css" media="screen">
|
||||
<script type="text/javascript" src="/javascripts/galleria/jquery.galleria.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -2,6 +2,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.resources :users
|
||||
map.resource :user_session
|
||||
map.resource :account, :controller => "users"
|
||||
map.signup "signup", :controller => "users", :action => "new"
|
||||
map.login "login", :controller => "user_sessions", :action => "new"
|
||||
map.logout "logout", :controller => "user_sessions", :action => "destroy"
|
||||
map.resources :photos
|
||||
|
|
Loading…
Reference in a new issue