diff --git a/Gemfile b/Gemfile index dd4ef8f..dd3cfbd 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,9 @@ gem 'cancancan' # Haml for templating! gem "haml-rails", "~> 0.9" +# Friendly ids! +gem 'friendly_id', '~> 5.1.0' + # Pure for css gem 'purecss-rails' # Use datatables diff --git a/Gemfile.lock b/Gemfile.lock index 284d8f7..9f81a45 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,8 @@ GEM i18n (~> 0.5) faraday (0.9.1) multipart-post (>= 1.2, < 3) + friendly_id (5.1.0) + activerecord (>= 4.0.0) globalid (0.3.6) activesupport (>= 4.1.0) haml (4.0.7) @@ -299,6 +301,7 @@ DEPENDENCIES devise factory_girl_rails faker + friendly_id (~> 5.1.0) haml-rails (~> 0.9) high_voltage (~> 2.4.0) jbuilder (~> 2.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0b697fd..fa00f9f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,10 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception rescue_from CanCan::AccessDenied do |exception| - redirect_to root_url, alert: exception.message + respond_to do |format| + format.json { render nothing: true, status: :forbidden } + format.html { redirect_to root_url, alert: exception.message } + end end def authenticate_user_or_client! diff --git a/app/controllers/concerns/data_table.rb b/app/controllers/concerns/data_table.rb index ff2b31c..b98d681 100644 --- a/app/controllers/concerns/data_table.rb +++ b/app/controllers/concerns/data_table.rb @@ -86,7 +86,7 @@ class DataTable } if type == 'number-range' h[:lower], h[:upper] = value.split('~').map do |euros| - (euros.to_f * 100).to_i rescue nil + (Float(euros) * 100).to_i rescue nil end elsif type == 'date-range' h[:lower], h[:upper] = value.split('~').map do |string| diff --git a/app/models/user.rb b/app/models/user.rb index c5886cf..54cfebb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,6 +11,8 @@ # class User < ActiveRecord::Base + include FriendlyId + friendly_id :name, use: :finders devise :timeoutable, :omniauthable, :omniauth_providers => [:zeuswpi] has_many :incoming_transactions, class_name: 'Transaction', foreign_key: 'creditor_id' diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 9da573b..9ecf696 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -76,7 +76,7 @@ { targets: 1, render: function(data, type, full, meta) { - return data/100; + return (data/100).toFixed(2); } } ]