ruby-on-rails-5.2

Rails filtering records in many to many relationship

旧时模样 提交于 2019-12-11 04:14:04
问题 I have many to many relationship for books and authors like: class Book < ApplicationRecord has_many :books_authors, inverse_of: :author, dependent: :destroy has_many :authors, through: :books_authors end class Author < ApplicationRecord has_many :books_authors, dependent: :destroy has_many :books, through: :books_authors end class AuthorsBook < ApplicationRecord belongs_to :author belongs_to :book end Now to get all the Books with Authors of ids: 1 and 3 The query is like : Book.joins(

ActiveStorage for S3 private files

可紊 提交于 2019-12-10 18:43:09
问题 Until now I was using Paperclip for uploading some files to S3. Some of these files are not public and Paperclip allowed to upload some files as private with the following bit : has_attached_file :image, styles: { large: "2000x2000", small: "1200x1200", thumb: "250x250"}, :s3_permissions => :private Now Paperclip is deprecated I am considering switching to Active Storage though I have not found any option to make some of my files private. Is there something to tweak in Active Storage to allow

Rails 5.2 some controller actions gives InvalidAuthenticityToken

↘锁芯ラ 提交于 2019-12-10 09:43:35
问题 Previously I used a gem which provided a controller for accepting external services to POST some data into our app. However in Rails 5.2 it stopped working. When the endpoint is triggered, it raises ActionController::InvalidAuthenticityToken error. 回答1: For Rails before 5.2, the generated ApplicationController will call protect_from_forgery , meaning POST,PUT,DELETE actions are checked for authenticity. New Rails 5.2 projects will by default check authenticity token for any subclass of

Rails 5.2 encrypted credentials not saving

大憨熊 提交于 2019-12-10 02:39:47
问题 When I do bin/rails credentials:edit my editor opens a file like credentials.yml.enc.1234 with default content. After I'm done editing, I hit save, and the console reads New credentials encrypted and saved. After I run bin/rails credentials:edit again, another temp file gets opened ( credentials.yml.enc.4321 ) and the contents are back to default. How can I make the credentials persist? 回答1: There is an issue related to this: https://github.com/rails/rails/issues/31286 It's been fixed already

Cannot edit rails credentials Rails 5.2

断了今生、忘了曾经 提交于 2019-12-09 05:54:55
问题 I am working on a Rails 5.2 app and I have installed and setup active_storage, however, I can't seem to edit or show the rails credentials. Here is an output of the error ben@ben-VirtualBox:~/Desktop/benbagley$ EDITOR="atom --wait" rails credentials:edit Traceback (most recent call last): 38: from bin/rails:3:in `<main>' 37: from bin/rails:3:in `load' 36: from /home/ben/Desktop/benbagley/bin/spring:15:in `<top (required)>' 35: from /home/ben/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core

How are joins in scopes in Rails 5.2 different from rails 5.1?

时光怂恿深爱的人放手 提交于 2019-12-06 12:02:29
After I upgraded rails from 5.1 to 5.2 I started getting the following error: NoMethodError: undefined method `expr' for nil:NilClass from /gems_path/activerecord-5.2.0/lib/active_record/associations/join_dependency/join_association.rb:47:in `block in join_constraints' from /gems_path/activerecord-5.2.0/lib/active_record/associations/join_dependency/join_association.rb:33:in `reverse_each' from /gems_path/activerecord-5.2.0/lib/active_record/associations/join_dependency/join_association.rb:33:in `join_constraints' from /gems_path/activerecord-5.2.0/lib/active_record/associations/join

Rails 5.2 some controller actions gives InvalidAuthenticityToken

烈酒焚心 提交于 2019-12-05 20:57:36
Previously I used a gem which provided a controller for accepting external services to POST some data into our app. However in Rails 5.2 it stopped working. When the endpoint is triggered, it raises ActionController::InvalidAuthenticityToken error. lulalala For Rails before 5.2, the generated ApplicationController will call protect_from_forgery , meaning POST,PUT,DELETE actions are checked for authenticity. New Rails 5.2 projects will by default check authenticity token for any subclass of ActionController::Base instead, which affects many existing Gems. You can wait for the gem updates for

Rails 5.2 encrypted credentials not saving

浪尽此生 提交于 2019-12-05 03:09:55
When I do bin/rails credentials:edit my editor opens a file like credentials.yml.enc.1234 with default content. After I'm done editing, I hit save, and the console reads New credentials encrypted and saved. After I run bin/rails credentials:edit again, another temp file gets opened ( credentials.yml.enc.4321 ) and the contents are back to default. How can I make the credentials persist? There is an issue related to this: https://github.com/rails/rails/issues/31286 It's been fixed already in 5.2.0.rc1 If you aren't using vim , you need to add a wait flag to the editor: EDITOR="atom --wait"

Cannot edit rails credentials Rails 5.2

一个人想着一个人 提交于 2019-12-03 08:12:39
I am working on a Rails 5.2 app and I have installed and setup active_storage, however, I can't seem to edit or show the rails credentials. Here is an output of the error ben@ben-VirtualBox:~/Desktop/benbagley$ EDITOR="atom --wait" rails credentials:edit Traceback (most recent call last): 38: from bin/rails:3:in `<main>' 37: from bin/rails:3:in `load' 36: from /home/ben/Desktop/benbagley/bin/spring:15:in `<top (required)>' 35: from /home/ben/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require' 34: from /home/ben/.rbenv/versions/2.5.0/lib/ruby/2.5.0/rubygems

ActiveStorage File Attachment Validation

╄→尐↘猪︶ㄣ 提交于 2019-12-02 19:16:51
Is there a way to validate attachments with ActiveStorage? For example, if I want to validate the content type or the file size? Something like Paperclip's approach would be great! validates_attachment_content_type :logo, content_type: /\Aimage\/.*\Z/ validates_attachment_size :logo, less_than: 1.megabytes Well, it ain't pretty, but this may be necessary until they bake in some validation: validate :logo_validation def logo_validation if logo.attached? if logo.blob.byte_size > 1000000 logo.purge errors[:base] << 'Too big' elsif !logo.blob.content_type.starts_with?('image/') logo.purge errors[