Class: Routepath

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/routepath.rb

Class Method Summary collapse

Class Method Details

.check(controller, action, method = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'app/models/routepath.rb', line 24

def self.check(controller, action, method=nil)
  if method.blank?
    return !Routepath.where(controller: controller, action: action).exists?
  else
    return !Routepath.where(controller: controller, action: action, method: method).exists?
  end
end

.seedObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/routepath.rb', line 7

def self.seed
  Rails.application.routes.routes.each do |route|
    controller = route.defaults[:controller]
    action = route.defaults[:action]
    #method = "#{route.constraints[:request_method]}".gsub("(?-mix:^","").gsub("$)","")
    method = route.verb
    if controller && action && method
      next if controller.length>=5 && controller[0, 5]=="rails"
      if Routepath.where(controller: controller, action: action, method: method).blank?
        puts "create---#{controller}|---#{action}|--#{method}"
        Routepath.create!(controller: controller, action: action, method: method)
      end
    end
  end
  return ""
end