OSDN Git Service

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