ruby-on-rails-5.1

Ruby 2.4 Enumerable#sum breaks in Rails 5.1

余生颓废 提交于 2021-02-07 20:11:36
问题 In Rails 5.1.4 using Ruby 2.3.5, I get this behavior: >> [].sum #> nil I'd like to upgrade to Ruby 2.4, where Enumerable#sum is implemented natively. Testing this in IRB using Ruby 2.4.2, I get this result: >> [].sum #> 0 That's OK, and I can handle the different result. But going back to the Rails console in Rails 5.1.4 using Ruby 2.4.2, I get this: >> [].sum #> NoMethodError: undefined method `each' for nil:NilClass However, in a newly created Rails 5.1.4 project, I don't get this error.

Adding an image_tag for the inline background-image url in Rails 5 template

余生颓废 提交于 2021-01-28 10:44:13
问题 I need to set the background image inline using the style tag, but it needs to reference an image object and not a fixed image from the assets folder. Below is my code to show what I am attempting to do. <div class="background-image-holder" style="background: url(#{" image_path @product.photo_one_url(:original)"}); opacity: 1;"> <%= image_tag(@product.photo_one_url(:medium)) %> </div> 回答1: I always prefer to use a content_tag if I'm including something dynamic like this, i.e. <%= content_tag

Adding an image_tag for the inline background-image url in Rails 5 template

我是研究僧i 提交于 2021-01-28 10:42:15
问题 I need to set the background image inline using the style tag, but it needs to reference an image object and not a fixed image from the assets folder. Below is my code to show what I am attempting to do. <div class="background-image-holder" style="background: url(#{" image_path @product.photo_one_url(:original)"}); opacity: 1;"> <%= image_tag(@product.photo_one_url(:medium)) %> </div> 回答1: I always prefer to use a content_tag if I'm including something dynamic like this, i.e. <%= content_tag

undefined method `map' for #<ActionController::Parameters> Rails 5.1

柔情痞子 提交于 2020-07-05 03:02:11
问题 I am upgrading my rails application from 3.2.2 to 5.1.4. I am gettign error on map method by using on params directly. Error: undefined method `map' for ActionController::Parameters On following line. @assignments= params[:assignments].map {|_k, value| Assignment.new(value.merge assignment_params)} Any alternative to do that in rails 5.1? 回答1: You can try to convert params to hash by using to_unsafe_h : @assignments= params[:assignments].to_unsafe_h.map {|_k, value| Assignment.new(value.merge

undefined method `map' for #<ActionController::Parameters> Rails 5.1

前提是你 提交于 2020-07-05 03:01:31
问题 I am upgrading my rails application from 3.2.2 to 5.1.4. I am gettign error on map method by using on params directly. Error: undefined method `map' for ActionController::Parameters On following line. @assignments= params[:assignments].map {|_k, value| Assignment.new(value.merge assignment_params)} Any alternative to do that in rails 5.1? 回答1: You can try to convert params to hash by using to_unsafe_h : @assignments= params[:assignments].to_unsafe_h.map {|_k, value| Assignment.new(value.merge

How to properly test ActiveJob's retry_on method with rspec?

此生再无相见时 提交于 2020-05-14 14:57:29
问题 I have been attempting to test this method for the past few days with no luck. Another thing I'd like to be able to do is rescue the error that bubbles up after the final retry attempt is made. Please see my comments and code snippets below. Source code for retry_on is here as well for context. Here's the sample code and tests: my_job.rb retry_on Exception, wait: 2.hours, attempts: 3 do |job, exception| # some kind of rescue here after job.exceptions == 3 # then notify Bugsnag of failed final

How can I insert or store multiple ids in a single column in Rails?

和自甴很熟 提交于 2020-01-25 11:18:45
问题 How can I insert or save multiple ids as comma separated e.g (2,5,8,10) values in single column in database for many to many relationship? I am using active admin for resource management. 回答1: The has_many :through Association A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model. For example,

How to set class level variables in Rails initializer when using spring?

别来无恙 提交于 2020-01-24 23:47:56
问题 In my config/initializers/transaction_logger.rb I have the following code # config/initializers/transaction_logger.rb Transaction::Logger.logger = Transaction::Logger.new("log/transations.log") Every time I change the code and run the tests I get: Failure/Error: delegate :info, :warn, :debug, :error, to: :logger Module::DelegationError: #<Class:Transaction::Logger>#error delegated to logger.error, but logger is nil: Transaction::Logger I have to run spring stop and then re-run the test again

How do i fix in ruby on rails the undefined method `alias_method_chain' error?

让人想犯罪 __ 提交于 2020-01-15 05:34:06
问题 I have just cloned a github repo https://github.com/maxitron93/p2pcollective.com, as i was exploring this awesome p2p lending app i encountered an error NoMethodError: undefined method `alias_method_chain' for ActiveRecord::ConnectionAdapters::PostgreSQLColumn:Class both when migrationg db or raunning server. I'm using the cloud9 ide to avoid my pc environment. Running through a couple of solution posts, i updated my gem store with device and erubis but still returned back to that 'alias

Deploy Rails 5.1 / Webpacker app with Capistrano

牧云@^-^@ 提交于 2020-01-01 05:14:26
问题 I have an Ubuntu server to deploy my Rails projects. In my Ubuntu server I had RVM. Now I want to deploy new projects with Rails 5.1 and webpacker. To deploy this projects, I've installed NVM, npm and yarn in my Ubuntu server. In my Rails 5.1 / Webpacker project I have following gems for capistrano deployment: Gemfile group :development do gem 'capistrano-rails' gem 'capistrano-rvm' gem 'capistrano-passenger' gem 'capistrano-nvm', require: false gem 'capistrano-yarn' end In deploy.rb I've