This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'uri' | |
| class UrlFormatValidator < ActiveModel::EachValidator | |
| def validate_each(object, attribute, value) | |
| unless value =~ URI.regexp(['http']) | |
| object.errors.add(attribute, t('errors.messages.url_format')) | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NameFormatValidator < ActiveModel::EachValidator | |
| def validate_each(object, attribute, value) | |
| unless value =~ /^([^\d\s\<\>,;\.:\-_\@#\'\€\+\*°\^!\"§\$%&\/\|\\\(\)\[\]=\?\{\}]{1}[^\d\<\>,;:_\@#\€\+\*°\^!\"§\$%\/\|\\\(\)\[\]=\?\{\}]{1,})$/ | |
| object.errors.add(attribute, t('errors.messages.name_format')) | |
| end | |
| end | |
| end | |
| class StreetNumberFormatValidator < ActiveModel::EachValidator | |
| def validate_each(object, attribute, value) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def field_with_errors(object, method, &block) | |
| if block_given? | |
| if object.errors[method].empty? | |
| content = with_output_buffer(&block) | |
| content.html_safe | |
| else | |
| content = with_output_buffer(&block) | |
| content_tag(:span, content, :class => "field_with_errors") | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
| if html_tag =~ /<textarea/ | |
| html_tag | |
| else | |
| "<span class=\"field_with_errors\">#{html_tag}</span>".html_safe | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def new | |
| resource = build_resource | |
| clean_up_passwords(resource) | |
| if request.xhr? | |
| render :partial => "/#{resource_name.to_s.pluralize}/sessions/new" | |
| else | |
| respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new } | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private | |
| # Sets header to remove HTTPS force | |
| # Needed if we once set config.force_ssl = true (TTL: 1year) | |
| # (https://github.com/josh/rack-ssl/blob/master/lib/rack/ssl.rb) | |
| # Note: Setting this outside HTTPS has no effect | |
| def set_hsts_header | |
| if request.ssl? | |
| response.headers["Strict-Transport-Security"] = 'max-age=3600' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def after_sign_in_path_for(resource) | |
| if resource.is_a?(User) | |
| user_path(resource.id) | |
| else | |
| :home_index | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class << self | |
| def force_ssl(options = {}) | |
| host = options.delete(:host) | |
| before_filter(options) do | |
| if !request.ssl? | |
| redirect_options = {:protocol => 'https://', :host => request.host, :status => :moved_permanently} | |
| redirect_options.merge!(:host => host) if host | |
| redirect_to "#{redirect_options[:protocol]}#{redirect_options[:host]}#{request.fullpath}", :status => redirect_options[:status] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hash | |
| def to_sorted_array | |
| self.stringify_keys! | |
| self.sort{|a,b| a[1] <=> b[1]} | |
| end | |
| def to_ordered_hash | |
| self.stringify_keys! | |
| ActiveSupport::OrderedHash[self.to_sorted_array] |