ruby-on-rails

Price Validation for Rails 4

守給你的承諾、 提交于 2021-02-18 22:35:52
问题 I have a pieces model in my rails app, and each piece has a decimal called :price . I want to validate that this price is two decimal places, greater than 0, and is less than a million dollars. I have looked at numerous sources on Stack overflow, and whenever I type a decimal for these validations, for example, 4.99 , the price becomes 4.990000000000000213162820728030055761. This has happened for all the validations I have looked up. Is this because I need to specify my precision for the

How can I get a rails route to keep the extension as part of the id?

别来无恙 提交于 2021-02-18 22:04:23
问题 I have the following route defined: map.resources :images, :only => [ :index, :new, :destroy ] when I do a rake routes I get the following: image DELETE /images/:id(.:format) {:action=>"destroy", :controller=>"images"} My problem is, I would like to use file names as my :id including any extension. At the moment my ids are getting to the controller minus the extension. Is there any way I can customize the above map.resources to generate the following path: image DELETE /images/:id {:action=>

Cannot load Rails.config.active_storage.service

不羁岁月 提交于 2021-02-18 20:49:19
问题 I'm setting up a new rails 5.2 app utilising Active Storage and using AWS for the hosting of images in production. However, I'm having an issue with the app reading the credentials: 2018-07-06T08:11:52.625415+00:00 app[web.1]: ! Unable to load application: Aws::Sigv4::Errors::MissingCredentialsError: Cannot load `Rails.config.active_storage.service`: 2018-07-06T08:11:52.625432+00:00 app[web.1]: missing credentials, provide credentials with one of the following options: 2018-07-06T08:11:52

How to set simple_form input default value

怎甘沉沦 提交于 2021-02-18 19:16:12
问题 = r.input :date_start do = r.text_field :date_start, id: 'date_start' How can I set default value for this? 回答1: = r.input :date_start, as: :string, input_html: {value: '01/01/2015', id: 'date_start'} 回答2: use this code: = r.input :date_start, as: :string, input_html: {id: 'date_start',value: '07/02/2015'} 回答3: Use of Safe Navigation or &. explained in this Answer to another question, is an option here; especially when chained with the || operator. Looking at the Answer from Kiry Meas Note: I

How to set simple_form input default value

柔情痞子 提交于 2021-02-18 19:15:29
问题 = r.input :date_start do = r.text_field :date_start, id: 'date_start' How can I set default value for this? 回答1: = r.input :date_start, as: :string, input_html: {value: '01/01/2015', id: 'date_start'} 回答2: use this code: = r.input :date_start, as: :string, input_html: {id: 'date_start',value: '07/02/2015'} 回答3: Use of Safe Navigation or &. explained in this Answer to another question, is an option here; especially when chained with the || operator. Looking at the Answer from Kiry Meas Note: I

Ruby install aborted due to missing extensions: openssl, readline, zlib compilation error

别等时光非礼了梦想. 提交于 2021-02-18 18:51:02
问题 I'm using macOs Catalina. I'm trying to install older version of Ruby (1.9.3, 2.1.2) via rbenv. However, I keep getting the errors below, when trying installing older version. *It was fine when installing 2.4 or newer. I already try brew install openssl brew install readline brew install zlib as well as brew update. I have everything installed and up-to-dated but still the errors below keeps coming up. I also did tried to install with configure option RUBY_CONFIGURE_OPTS="--with-readline-dir=

Ruby install aborted due to missing extensions: openssl, readline, zlib compilation error

僤鯓⒐⒋嵵緔 提交于 2021-02-18 18:50:54
问题 I'm using macOs Catalina. I'm trying to install older version of Ruby (1.9.3, 2.1.2) via rbenv. However, I keep getting the errors below, when trying installing older version. *It was fine when installing 2.4 or newer. I already try brew install openssl brew install readline brew install zlib as well as brew update. I have everything installed and up-to-dated but still the errors below keeps coming up. I also did tried to install with configure option RUBY_CONFIGURE_OPTS="--with-readline-dir=

Upload path based on a record value for Carrier wave Direct

江枫思渺然 提交于 2021-02-18 18:11:35
问题 I want to configure an upload path for Carrier wave Direct,which I am using to upload files directly to Amazon s3.In app/uploaders/myuploader.rb ,I have, def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end I want to modify this so that,the path looks like, "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{User.name}". so it will be some thing like, "uploads/Users/avatar/michael_jordan/.." Where User is the model in which the uploader is mounted. I have

Sidekiq to execute at specific time in every timezones

三世轮回 提交于 2021-02-18 17:21:22
问题 Using Sidekiq, what are the strategy to have it execute at a particular time in every time zone? For example, I need Sidekiq to perform a task every day at the following time and time zones across the world: ... 8:00 PM EST 8:00 PM CST 8:00 PM MST 8:00 PM PST ... 回答1: I would just run the same job at the start of each hour. You might want to use cron to run the job each hour or have a look at this list on how to create recurring jobs in Sidekiq. The first step within the job is to figure out

TinyMCE and Bootstrap Modals — Works only one time

旧巷老猫 提交于 2021-02-18 12:17:08
问题 I'm using Bootstrap and tinymce-rails so that I can have a nice text editor for some of my text areas. However, I'm having a modal render a form that contains a textarea and the "tinymce" class, but this modal only actually shows the TinyMCE text editor one time. Once the modal is closed and re-opened, it only looks like a regular text field. Here's the form that's being rendered: <%= form_for @paragraph_section, html: {class: "form-horizontal"} do |f| %> <div class="form-group"> <%= f.label