• R/O
  • HTTP
  • SSH
  • HTTPS

pettanr: コミット

サーバ側、Railsシステム本体


コミットメタ情報

リビジョン3bb159eda799aa3c5f19edb73ca9e44fbb6988db (tree)
日時2012-01-15 14:42:01
作者yasushiito <yas@pen-...>
コミッターyasushiito

ログメッセージ

iroiro

変更サマリ

差分

--- /dev/null
+++ b/app/assets/javascripts/author_registrations.js.coffee
@@ -0,0 +1,3 @@
1+# Place all the behaviors and hooks related to the matching controller here.
2+# All this logic will automatically be available in application.js.
3+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
--- /dev/null
+++ b/app/assets/stylesheets/author_registrations.css.scss
@@ -0,0 +1,3 @@
1+// Place all the styles related to the author_registrations controller here.
2+// They will automatically be included in application.css.
3+// You can use Sass (SCSS) here: http://sass-lang.com/
--- /dev/null
+++ b/app/controllers/author_registrations_controller.rb
@@ -0,0 +1,7 @@
1+class AuthorRegistrationsController < Devise::RegistrationsController
2+ protected
3+
4+ def after_sign_up_path_for(resource)
5+ '/home/step2'
6+ end
7+end
--- a/app/controllers/authors_controller.rb
+++ b/app/controllers/authors_controller.rb
@@ -33,5 +33,5 @@ class AuthorsController < ApplicationController
3333 format.html { render layout: 'system' }
3434 end
3535 end
36-
36+
3737 end
--- a/app/controllers/comics_controller.rb
+++ b/app/controllers/comics_controller.rb
@@ -11,7 +11,12 @@ class ComicsController < ApplicationController
1111 public
1212
1313 def top
14- @comics = Comic.all
14+ @new_comics = Comic.find(:all,
15+ :include => :author, :conditions => ['visible = 1'], :order => 'updated_at desc', :limit => 5
16+ )
17+ @new_pictures = OriginalPicture.find(:all,
18+ :include => [:artist, :lisence, :resource_picture], :order => 'updated_at', :limit => 5
19+ )
1520
1621 respond_to do |format|
1722 format.html # index.html.erb
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -1,8 +1,8 @@
11 class HomeController < ApplicationController
2-
3- def start
4-
5- end
2+ before_filter :authenticate_author!, :only => [
3+ :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3,
4+ :comic, :picture
5+ ]
66
77 def index
88 end
@@ -10,4 +10,93 @@ class HomeController < ApplicationController
1010 def profile
1111 end
1212
13+ def configure
14+ end
15+
16+ def create_token
17+ @author = current_author
18+ respond_to do |format|
19+ if @author.create_token
20+ format.html { redirect_to({:action => :configure}, {:notice => 'author token was successfully created.'}) }
21+ else
22+ format.html { render action: "auth_token" }
23+ end
24+ end
25+ end
26+
27+ def delete_token
28+ current_author.delete_token
29+ respond_to do |format|
30+ format.html { redirect_to :action => :configure}
31+ end
32+ end
33+
34+ def step2
35+ @author = current_author
36+ end
37+
38+ def save_step2
39+ @author = current_author
40+ respond_to do |format|
41+ if @author.step2(params[:author][:name])
42+ a = if params[:step3].to_i == 1
43+ :step3
44+ else
45+ :index
46+ end
47+ format.html { redirect_to({:action => a}, {:notice => 'your name was successfully updated.'}) }
48+ else
49+ format.html { render action: "step2" }
50+ end
51+ end
52+ end
53+
54+ def step3
55+ @artist = Artist.new :author_id => current_author.id, :name => current_author.name, :default_lisence_id => 1
56+ end
57+
58+ def save_step3
59+ if current_author.artist?
60+ redirect_to :action => :index
61+ else
62+ @artist = Artist.new params[:artist]
63+ respond_to do |format|
64+ if @artist.save
65+ format.html { redirect_to({:action => :index}, {:notice => 'artist was successfully registered.'}) }
66+ else
67+ format.html { render action: "step3" }
68+ end
69+ end
70+ end
71+ end
72+
73+ def comic
74+ @comics = Comic.find(:all,
75+ :include => :author, :conditions => ['author_id = ?', current_author.id],
76+ :order => 'updated_at desc', :limit => 20
77+ )
78+
79+ respond_to do |format|
80+ format.html # index.html.erb
81+ format.json { render json: @comics }
82+ end
83+ end
84+
85+ def picture
86+ if current_author.artist?
87+ @original_pictures = OriginalPicture.find(:all,
88+ :include => [:artist, :lisence, :resource_picture], :conditions => ['artist_id = ?', current_author.artist.id],
89+ :order => 'updated_at', :limit => 20
90+ )
91+
92+ respond_to do |format|
93+ format.html # index.html.erb
94+ format.json { render :json => @original_pictures.to_json(
95+ :include => [:resource_picture, :artist, :lisence]
96+ ) }
97+ end
98+ else
99+ end
100+ end
101+
13102 end
--- a/app/controllers/system_controller.rb
+++ b/app/controllers/system_controller.rb
@@ -4,7 +4,19 @@ class SystemController < ApplicationController
44 #layout :system
55
66 def start
7-
7+ OriginalPicture.all.each do |a|
8+ a.lisence_id = 1 if a.lisence_id.blank?
9+ a.save
10+ end
11+ ResourcePicture.all.each do |a|
12+ a.lisence_id = 1 if a.lisence_id.blank?
13+ a.artist_id = 1 if a.artist_id.blank?
14+ a.save
15+ end
16+ Artist.all.each do |a|
17+ a.default_lisence_id = 1 if a.default_lisence_id.blank?
18+ a.save
19+ end
820 end
921
1022 def index
--- /dev/null
+++ b/app/helpers/author_registrations_helper.rb
@@ -0,0 +1,2 @@
1+module AuthorRegistrationsHelper
2+end
--- a/app/models/author.rb
+++ b/app/models/author.rb
@@ -7,15 +7,29 @@ class Author < ActiveRecord::Base
77 :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable
88
99 # Setup accessible (or protected) attributes for your model
10- attr_accessible :email, :password, :password_confirmation, :remember_me
10+ attr_accessible :id, :name, :password, :password_confirmation, :remember_me #, :email
1111
12- before_save :ensure_authentication_token
1312 before_save do |r|
1413 r.name = 'no name' if r.name.blank?
1514 end
1615
17- def artist?
18- Artist.find_by_author(self) != nil
19- end
20-
16+ def artist?
17+ Artist.find_by_author(self) != nil
18+ end
19+
20+ def create_token
21+ self.ensure_authentication_token
22+ self.save
23+ end
24+
25+ def delete_token
26+ self.authentication_token = nil
27+ self.save
28+ end
29+
30+ def step2 n
31+ self.name = n
32+ self.save
33+ end
34+
2135 end
--- a/app/models/comic.rb
+++ b/app/models/comic.rb
@@ -11,4 +11,8 @@ class Comic < ActiveRecord::Base
1111 editable == 1 ? 'O' : 'X'
1212 end
1313
14+ def disp_visible
15+ visible == 1 ? 'O' : 'X'
16+ end
17+
1418 end
--- a/app/views/artists/list.html.erb
+++ b/app/views/artists/list.html.erb
@@ -20,9 +20,9 @@
2020 <td><%= h artist.email %></td>
2121 <td><%= h artist.name %></td>
2222 <td><%= h artist.homepage_url %></td>
23+ <td><%= h artist.api_url %></td>
2324 <td><%= link_to artist.default_lisence_id, :controller => 'lisences', :action => :browse, :id => artist.default_lisence_id %></td>
2425 <td><%= artist.crowled_at %></td>
25- <td><%= h artist.api_url %></td>
2626 <td><%= link_to artist.author_id, :controller => 'authors', :action => :browse, :id => artist.author_id %></td>
2727 <td><%= artist.created_at %></td>
2828 <td><%= artist.updated_at %></td>
--- /dev/null
+++ b/app/views/author_registrations/new.html.erb
@@ -0,0 +1,18 @@
1+<h2>Sign up</h2>
2+
3+<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4+ <%= devise_error_messages! %>
5+
6+ <div><%= f.label :email %><br />
7+ <%= f.email_field :email %></div>
8+
9+ <div><%= f.label :password %><br />
10+ <%= f.password_field :password %></div>
11+
12+ <div><%= f.label :password_confirmation %><br />
13+ <%= f.password_field :password_confirmation %></div>
14+
15+ <div><%= f.submit "Sign up" %></div>
16+<% end %>
17+
18+<%= render :partial => "devise/shared/links" %>
--- a/app/views/authors/registrations/new.html.erb
+++ b/app/views/authors/registrations/new.html.erb
@@ -3,9 +3,6 @@
33 <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
44 <%= devise_error_messages! %>
55
6- <div><%= f.label :name %><br />
7- <%= f.text_field :name %></div>
8-
96 <div><%= f.label :email %><br />
107 <%= f.email_field :email %></div>
118
--- a/app/views/comics/top.html.erb
+++ b/app/views/comics/top.html.erb
@@ -1,5 +1,6 @@
1-<h1><%= link_to '新着', comics_path %></h1>
2-
1+<%= link_to "comics", comics_path %>
2+<h1>コミック</h1>
3+<%= link_to '新着', comics_path %>
34 <table>
45 <tr>
56 <th>Title</th>
@@ -9,7 +10,7 @@
910 <th></th>
1011 </tr>
1112
12-<% @comics.each do |comic| %>
13+<% @new_comics.each do |comic| %>
1314 <tr>
1415 <td><%= link_to h(comic.title), :action => :play, :id => comic.id %></td>
1516 <td><%= comic.editable %></td>
@@ -25,5 +26,17 @@
2526 </tr>
2627 <% end %>
2728 </table>
28-<h1>人気</h1>
29-
29+<%= link_to '人気', comics_path %>
30+<h3>コマ</h3>
31+<%= link_to '新着', panels_path %>
32+<%= link_to '人気', panels_path %>
33+<h1>素材</h1>
34+<% @new_pictures.each do |picture| %>
35+ <div>
36+ <img src="<%= picture.resource_picture.url('thumbnail') -%>">
37+ 画:<%= h picture.artist.name %>
38+ </div>
39+<% end %>
40+<%= link_to "もっと見る", original_pictures_path %>
41+<h3>ライセンス</h3>
42+<%= link_to "lisences", lisences_path %>
--- /dev/null
+++ b/app/views/home/comic.html.erb
@@ -0,0 +1,14 @@
1+<h1>Listing comics</h1>
2+
3+<% @comics.each do |comic| %>
4+ <div>
5+ <div>
6+ <%= link_to h(comic.title), :action => :play, :id => comic.id %>
7+ 一般投稿:<%= comic.disp_editable %>
8+ 公開:<%= comic.disp_visible %>
9+ </div>
10+ <div>
11+ 更新:<%= comic.updated_at %>
12+ </div>
13+ </div>
14+<% end %>
--- /dev/null
+++ b/app/views/home/configure.html.erb
@@ -0,0 +1,15 @@
1+<h2>認証トークン</h2>
2+<div>
3+あなたの認証トークンは<%= current_author.authentication_token %>です
4+</div>
5+<div>
6+ <% if current_author.authentication_token %>
7+ <%= link_to 'delete token', :action => :delete_token %>
8+ <% else %>
9+ <%= link_to 'generate token', :action => :create_token %>
10+ <% end %>
11+</div>
12+<h2>退会</h2>
13+<div>
14+ <%= link_to('退会する', {:controller => 'author_registrations', :action => :destroy, :id => current_author.id}, {:method => :delete}) %>
15+</div>
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -1,7 +1,4 @@
11 <h1><%= h(current_author.name) -%>(<%= h(current_author.email) -%>)</h1>
2-<div>
3-あなたの認証トークンは<%= current_author.authentication_token %>です
4-</div>
52
63 <div>
74 <p>絵師活動</p>
--- /dev/null
+++ b/app/views/home/picture.html.erb
@@ -0,0 +1,10 @@
1+<h1>Listing my pictures</h1>
2+
3+<% @original_pictures.each do |original_picture| %>
4+ <div>
5+ <%= original_picture.filename %>
6+ <img src="<%= original_picture.resource_picture.url('thumbnail') -%>">
7+ <%= original_picture.width %>x<%= original_picture.height %>
8+ <%= original_picture.filesize %>bytes
9+ </div>
10+<% end %>
--- /dev/null
+++ b/app/views/home/step2.html.erb
@@ -0,0 +1,32 @@
1+<h1>ようこそ、ぺったんRへ</h1>
2+<div>
3+<%= h(current_author.email) -%>さんはぺったんRで作家としてデビューしました。
4+今すぐにでも作品を作れますが、より良い活動をするために作家名を登録してください。
5+</div>
6+<%= form_for(:author, :url => {:controller => '/home', :action => :save_step2}) do |f| %>
7+ <% if @author.errors.any? %>
8+ <div id="error_explanation">
9+ <h2><%= pluralize(@author.errors.count, "error") %> prohibited this original_lisence from being saved:</h2>
10+
11+ <ul>
12+ <% @author.errors.full_messages.each do |msg| %>
13+ <li><%= msg %></li>
14+ <% end %>
15+ </ul>
16+ </div>
17+ <% end %>
18+
19+ <div class="field">
20+ <%= f.label :name %><br />
21+ <%= f.text_field :name %>
22+ </div>
23+ <p>あなたの素材を投稿してみませんか?</p>
24+ 絵師としての情報を登録すれば、あなたのキャラクターを漫画に登場させるなど、幅広い創作活動ができます。
25+ <div class="field">
26+ <%= check_box_tag 'step3', 1, false %> 引き続き、絵師登録を行う
27+ </div>
28+
29+ <div class="actions">
30+ <%= f.submit '次のステップへ' %>
31+ </div>
32+<% end %>
--- /dev/null
+++ b/app/views/home/step3.html.erb
@@ -0,0 +1,31 @@
1+<h1>ようこそ、ぺったんRへ</h1>
2+<%= h(current_author.name) -%>さん
3+<div>
4+ <%= form_for(:artist, :url => {:controller => '/home', :action => :save_step3}) do |f| %>
5+ <% if @artist.errors.any? %>
6+ <div id="error_explanation">
7+ <h2><%= pluralize(@artist.errors.count, "error") %> prohibited this artist from being saved:</h2>
8+
9+ <ul>
10+ <% @artist.errors.full_messages.each do |msg| %>
11+ <li><%= msg %></li>
12+ <% end %>
13+ </ul>
14+ </div>
15+ <% end %>
16+
17+ <div class="field">
18+ <p>作家名とは別に絵師としてのペンネームを設定できます。</p>
19+ <%= f.label :name %><br />
20+ <%= f.text_field :name %><br />
21+
22+ <p>素材をアップロードするときのデフォルトライセンスを選択します。</p>
23+ <%= f.label :default_lisence_id %><br />
24+ <%= f.select :default_lisence_id, Lisence.all.map {|l| [l.name, l.id] }, :html => {:selected => @artist.default_lisence_id} %>
25+ <%= f.hidden_field :author_id, :value => @artist.author_id %>
26+ </div>
27+ <div class="actions">
28+ <%= f.submit '完了' %>
29+ </div>
30+ <% end %>
31+</div>
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -12,12 +12,21 @@
1212 <div>
1313 <% if author_signed_in? %>
1414 <%= link_to "my home", :controller => '/home' %>
15+ <%= link_to "my comics", :controller => '/home', :action => :comic %>
16+ <%= link_to "my pictures", :controller => '/home', :action => :picture %>
17+ <%= link_to "config", :controller => '/home', :action => :configure %>
1518 <%= link_to "ログアウト", destroy_author_session_path, :method => :delete %>
1619 <% else %>
1720 <%= link_to "ログイン", new_author_session_path %>
1821 <% end %>
1922 </div>
2023 <div>
24+ <p class="notice"><%= notice %></p>
25+ <p class="alert"><%= alert %></p>
26+</div>
27+<%= yield %>
28+
29+<div>
2130 <% if admin_signed_in? %>
2231 <%= link_to "system", :controller => '/system' %>
2332 <%= link_to "ログアウト", destroy_admin_session_path, :method => :delete %>
@@ -25,15 +34,5 @@
2534 <%= link_to "管理者", new_admin_session_path %>
2635 <% end %>
2736 </div>
28-<div>
29- <p class="notice"><%= notice %></p>
30- <p class="alert"><%= alert %></p>
31-</div>
32-<%= link_to "comics", comics_path %>
33-<%= link_to "panels", panels_path %>
34-<%= link_to "pictures", original_pictures_path %>
35-<%= link_to "lisences", lisences_path %>
36-<%= yield %>
37-
3837 </body>
3938 </html>
--- a/app/views/original_pictures/_uploader.html.erb
+++ b/app/views/original_pictures/_uploader.html.erb
@@ -2,6 +2,8 @@
22 <% if current_author.artist? -%>
33 <%= form_tag( {:action => "create"} , { :multipart => true }) do %>
44 <label for="file">File to Upload</label> <%= file_field_tag "original_picture[file]" %>
5+ lisence
6+ <%= collection_select :original_picture, :lisence_id, Lisence.all.map {|l| [l.name, l.id] }, :last, :first, :html => {:selected => current_author.artist.default_lisence_id} %>
57 <%= submit_tag 'upload' -%>
68 <% end -%>
79 <% else -%>
--- a/app/views/original_pictures/index.html.erb
+++ b/app/views/original_pictures/index.html.erb
@@ -8,5 +8,6 @@
88 <%= original_picture.width %>x<%= original_picture.height %>
99 <%= original_picture.filesize %>bytes
1010 画:<%= h original_picture.artist.name %>
11+ lisence:<%= h Lisence.find(original_picture.lisence_id || 1).name %>
1112 </div>
1213 <% end %>
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,7 +1,7 @@
11 Pettanr::Application.routes.draw do
22
33 devise_for :admins
4- devise_for :authors
4+ devise_for :authors, :controllers => { :registrations => "author_registrations" }
55
66 match 'original_pictures/:id(.:format)/refresh' => 'original_pictures#refresh'
77
--- /dev/null
+++ b/spec/controllers/author_registrations_controller_spec.rb
@@ -0,0 +1,5 @@
1+require 'spec_helper'
2+
3+describe AuthorRegistrationsController do
4+
5+end
--- /dev/null
+++ b/spec/helpers/author_registrations_helper_spec.rb
@@ -0,0 +1,15 @@
1+require 'spec_helper'
2+
3+# Specs in this file have access to a helper object that includes
4+# the AuthorRegistrationsHelper. For example:
5+#
6+# describe AuthorRegistrationsHelper do
7+# describe "string concat" do
8+# it "concats two strings with spaces" do
9+# helper.concat_strings("this","that").should == "this that"
10+# end
11+# end
12+# end
13+describe AuthorRegistrationsHelper do
14+ pending "add some examples to (or delete) #{__FILE__}"
15+end
旧リポジトリブラウザで表示