<commit_before>module Cms
  class Page < ActiveRecord::Base
		validates_presence_of :title, :link_url
		validates_uniqueness_of :title, :link_url
  end
end<commit_msg>Add dynamic routes to pages. Does not work yet.<commit_after>module Cms
  class Page < ActiveRecord::Base
		validates_presence_of :title, :link_url
		validates_uniqueness_of :title, :link_url
    
    after_save :update_route

    def add_routeC
      new_route = ActionDispatch::Routing::RouteSet.add_route(title, route_options)
      ActionDispatch::Routing::Routes.routes.insert(0, new_route)
    end
  
  def remove_route
      ActionDispatch::Routing::RouteSet.clear! { |r| r.instance_variable_get(:@requirements)[:page_id] == id }
    end
  
    def update_route
      remove_route
      add_route
    end
    
    def route_options
      @route_options ||= { :controller     => link.controller, 
                           :action         => link.action, 
                           :link_id        => link_id,
                           :page_id        => id }
  end


  end
end
{'fraction_non_alphanumeric': 0.0835707502374169, 'fraction_numerical': 0.000949667616334283, 'mean_word_length': 2.5016611295681064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7111965', 'n_tokens_mistral': 331, 'n_tokens_neox': 325, 'n_words': 67}