ruby-on-rails-5.2

How to attach Base64 image to Active Storage object?

淺唱寂寞╮ 提交于 2020-04-17 17:54:53
问题 I can attach a png image from disc by and everything works just fine: obj.attachment.attach( io: File.open('dog.png'), filename: "image_name", content_type: "image/png" ) But it doesn't work giving result like too tiny empty square when I save a Base64 png image which encoded into String something like that "data:image/png;base64,iVB**..REST OF DATA..**kSuQmCC" by: obj.attachment.attach( io: StringIO.new(encoded_base_sixty_four_img), filename: "image_name", content_type: "image/png" ) Also I

How to configure Rails 5.2.1 server listen on all interfaces?

混江龙づ霸主 提交于 2020-04-13 06:59:00
问题 I'm still fairly new to RoR and learning so please bear with me if I have follow-up questions. Our Rails (v 5.0.2) app was configured to listen on all interfaces with this configuration in config/boot.rb : require 'rails/commands/server' module Rails class Server def default_options # make rails listen on all interfaces (accept connections from any ip) super.merge(Host: '0.0.0.0', Port: 1234) end end end I recently upgraded Rails from 5.0.2 to 5.2.1 and when I run rails s , I get: /Users/aum

How to configure Rails 5.2.1 server listen on all interfaces?

做~自己de王妃 提交于 2020-04-13 06:58:06
问题 I'm still fairly new to RoR and learning so please bear with me if I have follow-up questions. Our Rails (v 5.0.2) app was configured to listen on all interfaces with this configuration in config/boot.rb : require 'rails/commands/server' module Rails class Server def default_options # make rails listen on all interfaces (accept connections from any ip) super.merge(Host: '0.0.0.0', Port: 1234) end end end I recently upgraded Rails from 5.0.2 to 5.2.1 and when I run rails s , I get: /Users/aum

Rails 5.2 Active Storage direct upload failure: CORS header ‘Access-Control-Allow-Origin’ missing

牧云@^-^@ 提交于 2020-04-13 02:55:51
问题 I am trying out Rail 5.2.0.rc1 Active Storage, using its included JavaScript library to upload PDF docs directly from the client to the cloud. But on submitting a form I get a browser error in both Firefox & Chrome: Cross-Origin Request Blocked... (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Headers are set thus this.xhr.setRequestHeader... in the activestorage.js and dont appear to be configurable: https://github.com/rails/rails/blob/master/activestorage/app/javascript

Rails 5.2 application secrets empty at Heroku

泄露秘密 提交于 2020-03-05 04:15:08
问题 I deployed to Heroku with success but there is an issue with credentials. I added RAILS_MASTER_KEY env variable at Heroku app CONFIG VARS section and copy-pasted the value from my app master.key file: Then when I check its value from Heroku console, it is still nil: Loading production environment (Rails 5.2.3) irb(main):001:0> Rails.application.secrets.secret_key_base => nil irb(main):002:0> Rails.application.secrets => {:secret_key_base=>nil, :secret_token=>nil} irb(main):003:0> But when I

Getting filename before saving in ActiveStorage - Rails 5.2.1

拈花ヽ惹草 提交于 2020-01-25 08:42:25
问题 I am trying to get the name of the file uploaded by a user before ActiveStorage goes on to save it. The form is generated using form_with and is shown below: <%= form_with model: upload do |form| %> <div class=""> <%= form.file_field :files, multiple: true, direct_upload: true, required: true %> <%= form.label :files, '', class: 'icon ion-ios-cloud-upload' do %> <span>click the icon to select files</span> <% end %> <div class="actions"> <%= form.submit "Upload", class: "btn btn-primary" %> <

Merge record into ActiveRecord Relation

╄→尐↘猪︶ㄣ 提交于 2020-01-25 06:34:05
问题 I pull a record as: def self.imp_broadcast_preview! Broadcast.where(for_gamers: true).order(:created_at).last end And then in my controller I have: def index @conversations = Conversation.where(gamer: @gamer) @conversations << Broadcast.imp_broadcast_preview! end The above code works properly in Rails 4.2 and merges the last broadcast message in the conversations. I just updated my codebase to Rails 5.2 and now I am getting an error: NoMethodError (undefined method `<<' for #<Conversation:

Javascript in a fresh Rails 5.2.1 app on Heroku doesn't work properly

与世无争的帅哥 提交于 2020-01-25 05:45:05
问题 I think there is a big problem with JavaScript files in Rails 5 apps in Production environment on Heroku. It works locally though My configuration: Windows: 10 Education Rails: 5.2.1 Ruby: 2.4.4p296 Heroku: heroku/7.7.7 win32-x64 node-v10.7.0 postgres: postgres (PostgreSQL) 10.3 I will now present you the steps I made to confirm that it doesnt work and you can try for your self. In the end you will have a link to the bitbucket repo and the app on Heroku. Step 1: Creating a new Rails 5 App and

Getting error in logs ActiveSupport::MessageEncryptor::InvalidMessage when try to deploy Rails 5.2.0 App

谁说胖子不能爱 提交于 2020-01-15 10:47:25
问题 I'm trying to deploy a Rails 5.2.0 App on ec2 instance using mina deploy and When it tries to Migrate database it is aborted with following error logs. -----> Migrating database WARNING: Use strings for Figaro configuration. 2 was converted to "2". WARNING: Use strings for Figaro configuration. 5 was converted to "5". I, [2018-07-07T15:15:56.316810 #15933] INFO -- sentry: ** [Raven] Raven 2.7.4 ready to catch errors I, [2018-07-07T15:15:56.579121 #15933] INFO -- sentry: ** [Raven] Raven 2.7.4

Separate secret_key_base in Rails 5.2?

我的未来我决定 提交于 2020-01-01 08:05:02
问题 I just upgraded from 5.1 to 5.2 and I'm quite confused about this 'better' methodology to storing secrets... Maybe I'm not understanding, but it seems like now development and production have been 'merged' into a SINGLE SECRET_KEY_BASE as well as master.key ... is this correct? If not, how do I use a separate master key and SECRET_KEY_BASE in development? What if I have developers helping me and I don't want them to know my master key (or secrets) I use in production? 回答1: Rails 5.2 changed