ruby-on-rails-5

rails_admin with cancan not catching access denied exception for redirect

落花浮王杯 提交于 2020-08-27 07:07:10
问题 I am using rails 5, rails_admin, devise and cancancan. Everything works correctly, but when there is access denied, it shows a 'You are not authorized to access this page' error screen. I want to redirect to root_path, I've been searching and I only found that I have to write in app/controllers/application_controller.rb this code: class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| redirect_to root_path, :alert => exception.message end end And

rails_admin with cancan not catching access denied exception for redirect

假装没事ソ 提交于 2020-08-27 07:07:05
问题 I am using rails 5, rails_admin, devise and cancancan. Everything works correctly, but when there is access denied, it shows a 'You are not authorized to access this page' error screen. I want to redirect to root_path, I've been searching and I only found that I have to write in app/controllers/application_controller.rb this code: class ApplicationController < ActionController::Base rescue_from CanCan::AccessDenied do |exception| redirect_to root_path, :alert => exception.message end end And

Rails 5 form_for with checkbox array

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-25 07:28:45
问题 I am using a PostgreSQL database and Rails 5.0.6. I try to build a course allocation WebApp for the school where I am working. For each course the teachers are able to select which forms are allowed to visit the course. Migration file: def up create_table :courses do |t| t.integer :number, null: false t.string :name, null: false t.text :description, null: false t.decimal :level, array: true, default: [] t.integer :max_visitor, null: false t.integer :min_visitor t.integer :pos_visit t

Configuring ActiveStorage to use S3 with IAM role

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-24 09:17:26
问题 I'm trying to configure ActiveStorage to use S3 bucket as a storage backend however I don't want to pass any of access_key_id , secret_access_key , region . Instead, I'd like to use previously defined IAM role. Such configuration is mentioned here. It reads (I've added bold): If you want to use environment variables, standard SDK configuration files, profiles, IAM instance profiles or task roles, you can omit the access_key_id, secret_access_key, and region keys in the example above. The

Rails 5 using will_paginate to create a load more button

試著忘記壹切 提交于 2020-08-01 05:13:06
问题 So I'm trying to create a load more button (not infinite scroll although some simple js tweaks could make it so). I'm using the will_paginate gem in Rails 5. Its currently all working as expected except when I click load more it loads the next page posts twice e.g: Load more > Post 4, Post 5, Post 6, Post 4, Post 5, Post 6 FYI my 'posts' are @links: links_controller.erb def index @links = Link.order('created_at DESC').paginate(:page => params[:page], :per_page => 3) respond_to do |format|

Method sort_by is deprecated - Possible solutions?

你说的曾经没有我的故事 提交于 2020-07-22 07:52:05
问题 my current rails project is giving a warning of - DEPRECATION WARNING: Method sort_by is deprecated and will be removed in Rails 5.1, as ActionController::Parameters no longer inherits from hash. I've searched for this warning as well as potential fixes but can't find anything at all regarding it. I'm wondering if anybody here would have any suggestions, fixes or replacements for sort_by ? If this is an easy solution I apologies as I'm still learning rails. Thanks for taking the time to read