OSDN Git Service

125b159b9cf49a3037fcba2768e169b45128a6ba
[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 =begin
40   rescue_from ActiveRecord::RecordNotFound, :with => :render_404
41
42   private
43   def render_404(exception = nil)
44     if exception
45         logger.info "Rendering 404: #{exception.message}"
46     end
47     respond_to do |format|
48           format.html { 
49     render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
50 }
51           format.json { 
52     render :text => "404 found", :status => 404
53 }
54   end
55   end
56 =end  
57 end