OSDN Git Service

t#30102:update i18n op rp au ar gc gp pc
[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     @server_result = {
7       :location => {:controller => params[:controller], :action => params[:action]}
8     }
9     @server_result[:location][:id] = params[:id] if params[:id]
10     if Admin.count.to_i == 0 or License.count.to_i == 0
11       if params[:controller] == 'system' and params[:action] == 'start'
12       else
13         redirect_to :controller => '/system', :action => 'start'
14       end
15     else
16       if user_signed_in?
17         @user = current_user
18         @author = @user.author
19         @artist = if @author and @author.artist?
20           @author.artist
21         else
22           nil
23         end
24       end
25       @admin = if admin_signed_in?
26         current_admin
27       else
28         nil
29       end
30     end
31   end
32   
33   def authenticate_artist
34     if @author.artist?
35       true
36     else
37       respond_to do |format|
38         format.html { redirect_to main_app.new_artist_path, :status => :found }
39         format.js { render "artists/new" }
40         format.json { 
41           raise ActiveRecord::Forbidden
42         }
43       end
44       false
45     end
46   end
47   
48   def set_image(file)
49     if file.respond_to?(:read)
50       file.read
51     else
52       Base64.decode64(file.to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
53     end
54   end
55   
56 =begin
57   rescue_from ActiveRecord::RecordNotFound, :with => :render_404
58
59   private
60   def render_404(exception = nil)
61     if exception
62         logger.info "Rendering 404: #{exception.message}"
63     end
64     respond_to do |format|
65           format.html { 
66     render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
67 }
68           format.json { 
69     render :text => "404 found", :status => 404
70 }
71   end
72   end
73 =end  
74 end