OSDN Git Service

create demander
[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           Artist.new author_id: @author.id, email: @user.email, name: @author.name
23         end
24       end
25       @admin = if admin_signed_in?
26         current_admin
27       else
28         nil
29       end
30       @demand_user = if demand_user_signed_in?
31         current_demand_user
32       else
33         nil
34       end
35     end
36   end
37   
38   def authenticate_artist
39     if @author.artist?
40       true
41     else
42       respond_to do |format|
43         format.html { redirect_to main_app.new_artist_path, :status => :found }
44         format.js { render "artists/new" }
45         format.json { 
46           raise ActiveRecord::Forbidden
47         }
48       end
49       false
50     end
51   end
52   
53   def set_image(file)
54     if file.respond_to?(:read)
55       file.read
56     else
57       Base64.decode64(file.to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
58     end
59   end
60   
61 =begin
62   rescue_from ActiveRecord::RecordNotFound, :with => :render_404
63
64   private
65   def render_404(exception = nil)
66     if exception
67         logger.info "Rendering 404: #{exception.message}"
68     end
69     respond_to do |format|
70           format.html { 
71     render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
72 }
73           format.json { 
74     render :text => "404 found", :status => 404
75 }
76   end
77   end
78 =end  
79 end