Permalink
Browse files

add common method to application controller

  • Loading branch information...
1 parent 49b763b commit e8a678f12960de3aafaf6d83d04e5ff27f4df048 @xdite committed Dec 16, 2012
View
@@ -6,6 +6,7 @@ alpha
* update to bootstrap-helper 2.1.2.1
* remove newrelic_rpm
* rvm-capistrano
+ * replace devise.email_sender to Setting.email_sender
0.1.0 (Nov 12, 2012)
* add powder to Gemfile
View
@@ -6,7 +6,6 @@
- Facebook
* Devise
- Login Form refactor
- - replace sender to Setting.email_sender
* Cancan
* Testing Tool
* Social
@@ -6,8 +6,7 @@ class AppBuilder < Rails::AppBuilder
def raise_delivery_errors
- replace_in_file 'config/environments/development.rb',
- 'raise_delivery_errors = false', 'raise_delivery_errors = true'
+ replace_in_file 'config/environments/development.rb', 'raise_delivery_errors = false', 'raise_delivery_errors = true'
end
def add_common_rake_tasks
@@ -33,8 +32,10 @@ def create_database
def generate_devise
generate 'devise:install'
generate 'devise User'
- replace_in_file 'config/initializers/devise.rb', /config\.mailer_sender = \".+\"/ , "config.mailer_sender = Setting.email_sender"
+ end
+ def replace_email_sender_for_devise
+ replace_in_file 'config/initializers/devise.rb', /config\.mailer_sender = \".+\"/ , "config.mailer_sender = Setting.email_sender"
end
def gitignore_files
@@ -64,6 +65,10 @@ def create_initializers
directory 'initializers', 'config/initializers'
end
+ def add_common_method_to_application_controller
+ template 'application_controller_rb', 'app/controllers/application_controller.rb',:force => true
+ end
+
def remove_routes_comment_lines
replace_in_file 'config/routes.rb', /Application\.routes\.draw do.*end/m, "Application.routes.draw do\nend"
@@ -28,6 +28,7 @@ def bootstrappers_customization
invoke :configure_app
invoke :create_initializers
invoke :remove_routes_comment_lines
+ invoke :add_common_method_to_application_controller
invoke :setup_root_route
invoke :setup_git
end
@@ -72,8 +73,6 @@ def add_common_rake_tasks
build :add_common_rake_tasks
end
-
-
def customize_gemfile
build :add_custom_gems
build :add_devise_gem
@@ -109,19 +108,22 @@ def create_initializers
def setup_devise
build :generate_devise
+ build :replace_email_sender_for_devise
end
-
def customize_error_pages
say 'Customizing the 500/404/422 pages'
build :customize_error_pages
end
-
def remove_routes_comment_lines
build :remove_routes_comment_lines
end
+ def add_common_method_to_application_controller
+ build :add_common_method_to_application_controller
+ end
+
def setup_root_route
build :setup_root_route
end
@@ -0,0 +1,22 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+
+ def login_required
+ if current_user.blank?
+ respond_to do |format|
+ format.html {
+ authenticate_user!
+ }
+ format.js{
+ render :partial => "common/not_logined"
+ }
+ format.all {
+ head(:unauthorized)
+ }
+ end
+ end
+
+ end
+
+
+end

0 comments on commit e8a678f

Please sign in to comment.