OSDN Git Service

t#29400:itr3?
[pettanr/pettanr.git] / app / controllers / application_controller.rb
1 class ApplicationController < ActionController::Base
2   protect_from_forgery
3   before_filter :bf
4   
5   def bf
6     if Admin.count.to_i == 0 or License.count.to_i == 0
7       if params[:controller] == 'system' and params[:action] == 'start'
8       else
9         redirect_to :controller => '/system', :action => 'start'
10       end
11     else
12       if user_signed_in?
13         @user = current_user
14         @author = @user.author
15         @artist = if @author and @author.artist?
16           @author.artist
17         else
18           Artist.new author_id: @author.id, email: @user.email, name: @author.name
19         end
20       end
21     end
22   end
23   
24   def authenticate_artist
25     if @author.artist?
26       true
27     else
28       respond_to do |format|
29         format.html { redirect_to main_app.new_artist_path, :status => :found }
30         format.js { render "artists/new" }
31         format.json { 
32           raise ActiveRecord::Forbidden
33         }
34       end
35       false
36     end
37   end
38   
39   def set_image(file)
40     if file.respond_to?(:read)
41       file.read
42     else
43       Base64.decode64(file.to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
44     end
45   end
46   
47 =begin
48   rescue_from ActiveRecord::RecordNotFound, :with => :render_404
49
50   private
51   def render_404(exception = nil)
52     if exception
53         logger.info "Rendering 404: #{exception.message}"
54     end
55     respond_to do |format|
56           format.html { 
57     render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
58 }
59           format.json { 
60     render :text => "404 found", :status => 404
61 }
62   end
63   end
64 =end  
65 end