Module: DeviseUserGenerator::RoutesHelper
- Included in:
- Devise::Generators::UsersGenerator
- Defined in:
- lib/generators/devise/users/routes_helper.rb
Instance Method Summary collapse
- #default_signin_routes ⇒ Object
- #model_routes ⇒ Object
- #routes_configure! ⇒ Object
- #user_type_routes ⇒ Object
- #user_types_to_route ⇒ Object
Instance Method Details
#default_signin_routes ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/devise/users/routes_helper.rb', line 26 def default_signin_routes name_default_users = user_class.underscore.gsub('/', '_').pluralize default_user_class = user_class.classify %Q{ devise_for :#{name_default_users}, :class_name => '#{default_user_class}', :controllers => {:sessions => 'main'} do get '/sign_in' => 'main#index', :as => :new_user_session end} end |
#model_routes ⇒ Object
3 4 5 6 7 |
# File 'lib/generators/devise/users/routes_helper.rb', line 3 def model_routes arg = "#{user_class.pluralize.underscore}" # arg << ", :admins" if admin_user? arg end |
#routes_configure! ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/generators/devise/users/routes_helper.rb', line 9 def routes_configure! routes_content = default_signin_routes << user_type_routes puts "Insert into routes: #{routes_content}" insert_into_routes do routes_content end end |
#user_type_routes ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/devise/users/routes_helper.rb', line 44 def user_type_routes user_types_to_route.each do |user_type| name_user_types = user_type.pluralize if read_routes_file =~ /devise_for :#{name_user_types}/ debug! "removing old devise routing for: #{name_user_types}" File.remove_content_from routes_file, :where => /devise_for :#{name_user_types}/ end end debug! "performing devise role routing for: #{user_types_to_route}" user_types_to_route.map do |user_type| name_user_types = user_type.pluralize name_user_type = user_type.underscore.gsub('/', '_') %Q{ devise_for :#{name_user_types}, :class_name => '#{user_type.classify}', :controllers => {:registrations => 'devise/registrations', :sessions => 'main'} do match "/#{name_user_types}/sign_in" => "devise/sessions#new", :as => :#{name_user_type}_signin match "/#{name_user_types}/sign_up" => "devise/registrations#new", :as => :#{name_user_type}_signup end } end.join("\n") end |
#user_types_to_route ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/generators/devise/users/routes_helper.rb', line 17 def user_types_to_route @user_types_to_route ||= user_types_except(:guest).delete_if do |user_type| name_user_types = user_type.pluralize is_there = !(read_routes_file =~ /devise_for :#{name_user_types}, :class_name =>/).nil? debug! "not doing devise routing for #{name_user_types} as it is already there" if is_there is_there end end |