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
32 changed files
with
426 additions
and
47 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
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,88 @@ | ||
# -*- encoding: utf-8 -*- | ||
class AlbumsController < ApplicationController | ||
|
||
before_filter :authenticate_user! | ||
|
||
# GET /albums | ||
# GET /albums.json | ||
def index | ||
@albums = Album.all | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json { render json: @albums } | ||
end | ||
end | ||
|
||
# GET /albums/1 | ||
# GET /albums/1.json | ||
def show | ||
@album = Album.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json { render json: @album } | ||
end | ||
end | ||
|
||
# GET /albums/new | ||
# GET /albums/new.json | ||
def new | ||
@album = Album.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json { render json: @album } | ||
end | ||
end | ||
|
||
# GET /albums/1/edit | ||
def edit | ||
@album = Album.find(params[:id]) | ||
end | ||
|
||
# POST /albums | ||
# POST /albums.json | ||
def create | ||
@album = Album.new(params[:album]) | ||
@album.private = params[:private] | ||
|
||
respond_to do |format| | ||
if @album.save | ||
format.html { redirect_to @album, notice: '电影集创建成功.' } | ||
format.json { render json: @album, status: :created, location: @album } | ||
else | ||
format.html { render action: "new" } | ||
format.json { render json: @album.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# PUT /albums/1 | ||
# PUT /albums/1.json | ||
def update | ||
@album = Album.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @album.update_attributes(params[:album]) | ||
format.html { redirect_to @album, notice: 'Album was successfully updated.' } | ||
format.json { head :no_content } | ||
else | ||
format.html { render action: "edit" } | ||
format.json { render json: @album.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /albums/1 | ||
# DELETE /albums/1.json | ||
def destroy | ||
@album = Album.find(params[:id]) | ||
@album.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to albums_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
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,10 @@ | ||
class PhotosController < ApplicationController | ||
|
||
def index | ||
gon.images = Image.where("user_id = 1").all.map { |image| image.file.url('main') } | ||
token = params[:token] | ||
album = Album.find_by_token(token) | ||
images = album.images | ||
gon.images = images.map { |image| image.file.url('main') } | ||
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,5 @@ | ||
class WelcomeController < ApplicationController | ||
def index | ||
gon.images = Album.first.images.map { |image| image.file.url('main') } | ||
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,2 @@ | ||
module AlbumsHelper | ||
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,2 @@ | ||
module WelcomeHelper | ||
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,34 @@ | ||
class Album < ActiveRecord::Base | ||
attr_accessible :desc | ||
|
||
after_create :generate_token | ||
|
||
has_many :images | ||
|
||
#唯一url | ||
def url | ||
"http://localhost:3000/#{self.token}" | ||
end | ||
|
||
#生成唯一的token | ||
def generate_token | ||
begin | ||
self.token = Album.random | ||
self.save! | ||
rescue ActiveRecord::RecordNotUnique => e | ||
retry | ||
end | ||
end | ||
|
||
ID_LENGTH = 128 | ||
class << self | ||
def random(bitlength = ID_LENGTH) | ||
limit = 2 ** bitlength - 1 | ||
max_size = limit.to_s(36).size | ||
string = rand(limit).to_s(36) | ||
string = '0' + string while string.size < max_size | ||
string | ||
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 |
---|---|---|
|
@@ -6,5 +6,6 @@ class Image < ActiveRecord::Base | |
validates :file, :presence => true | ||
|
||
belongs_to :user | ||
belongs_to :album | ||
|
||
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,25 @@ | ||
<%= form_for(@album) do |f| %> | ||
<% if @album.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@album.errors.count, "error") %> 引起数据无法保存:</h2> | ||
<ul> | ||
<% @album.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :desc %><br /> | ||
<%= f.text_area :desc, :rows => 10, :cols => 40 %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :private %> | ||
<%= check_box_tag :private %> | ||
Tips: 如果设置隐私,那么别人将无法观看您的图片。 | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% 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,6 @@ | ||
<h1>Editing album</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @album %> | | ||
<%= link_to 'Back', albums_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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<h2>电影集列表</h2> | ||
<%= link_to '创建新电影集', new_album_path %> | ||
<table> | ||
<tr> | ||
<th>描述</th> | ||
<th>是否隐私</th> | ||
<th>唯一URL</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @albums.each do |album| %> | ||
<tr> | ||
<td><%= album.desc %></td> | ||
<td><%= album.private %></td> | ||
<td><%= album.url %></td> | ||
<td><%= link_to '显示', album_images_path(album) %></td> | ||
<td><%= link_to '修改', edit_album_path(album) %></td> | ||
<td><%= link_to '删除', album, confirm: '肯定删除?', method: :delete %></td> | ||
<td><%= link_to "上传图片", %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
|
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,5 @@ | ||
<h1>New album</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', albums_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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
<p> | ||
<b>Desc:</b> | ||
<%= @album.desc %> | ||
</p> | ||
|
||
<p> | ||
<b>Private:</b> | ||
<%= @album.private %> | ||
</p> | ||
|
||
<p> | ||
<b>Token:</b> | ||
<%= @album.token %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_album_path(@album) %> | | ||
<%= link_to 'Back', albums_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 |
---|---|---|
|
@@ -2,5 +2,3 @@ | |
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Show', @image %> | | ||
<%= link_to 'Back', images_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
Oops, something went wrong.