Sha256: 76a810a1b400c4422d37118dcbe069a78ec3923ef531c71e4b79a1dcf480f890

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

class Routepath < ActiveRecord::Base
  belongs_to :function
  validates :controller, :presence => {:message => "控制器不能为空"}
  validates :action, :presence => {:message => "动作不能为空"}
  validates :method, :presence => {:message => "请求方法不能为空"}

  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

  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

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
admin-sys-1.0.2 app/models/routepath.rb
admin-sys-1.0.1 app/models/routepath.rb
admin-sys-1.0.0 app/models/routepath.rb