Tag : ruby

I have a batch of character strings, and the rule is “number+letter+number+letter+number”. Numbers and letters can be any one or more, such as: 1A03F4F, 16DC203B5R. I want to regularly extract the first number, the first letter, the second number, the second letter and so on. How do you write it? String#scan 2.5.1 :017 > ’16DC203B5R’.scan(/(\d+)*([a-zA-Z]+)*/) ..

Read more

When I first came into contact with ruby, I saw my colleagues have this code when reviewing today: provider = campaign_type == :entry ? Settings.pay_method_to_provider[pay_method] : self.auth_provider It’s really hard to understand at a glance. . .What do you think? In general, when using the boolean-exp character, if the statement is longer, it can be ..

Read more

This is a review page of the school curriculum scoring system. I want to do the following:1. Count the number of words in each comment2. when the whole loop is over, count the total number of words in all comments <div id=”header”><h1>Course Rating Information </h1><p>Number:<%= @course.number %></p><p>Year:<%= @course.year %></p><p>Name:<%= @course.name %></p></div><div id=”pagebody”><% if @course.comments.exists? %><h2>Ratings</h2><% ..

Read more

Please observe the following codes: module A refine String def reverse self end end end using A p “abc”.reverse # => “abc” remove_using A p “abc”.reverse # => “cba” Is there such an effectremove_usingMethods? In order to dynamically eliminate the impact after using a refinement. According toObservation, it seems that this is intentional, because language ..

Read more

Environment: railwebpacker: vue+vuex+vue-router+iviewProblem: change the state value through mutation. through the vue browser debugging tool, you can see that mutation triggers normally, but the variable that computed obtains the corresponding state value is still the initial value of state Test: Pull out the project:https://github.com/gorails-screencasts/vuejs-trello-clone, in which test, performance is normal+++++++++++++++++++Like the vuejs-trello-clone project, turbolink was ..

Read more

Recently, I am studying elk and need to embed ruby code. I hope I can help you understand ruby. Please explain, thank you! Just explain what each of the following two parts represents. //The first one xx “xxx” do end //The second kind xx(“xxx”) do |xx| end The original code is as follows test “drop ..

Read more

I am new to Ruby on Rails. I have already deployed the project to Aliyun. The pictures of the website are stored by aws s3. In the process, I need to set some secret keys of AWS. I used figaro. My setup is like this: config/application.yml: production: SEND_CLOUD_USER_NAME: xxx SEND_CLOUD_USER_KEY: xxxxx secret_key_base: xxxxxxx AWS_ACCESS_KEY_ID: xxxxxxxx ..

Read more

Recently watchingrailstutorial.viarails g model User name:string email:stringThe generated model gradually became the following virtues along with the tutorial: class User < ApplicationRecord before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } #VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i validates :email, presence: true, length: { maximum: 255 }, format: { with: ..

Read more

Is this a Ruby project? If it can work, how will it work? The link is as follows´╝Ühttps://github.com/clarkgrubb … A typical Ruby project will have one under its root directory.GemfileFile, this project does not have. In addition, I checked the ruby file in this project and found only two scripts. From the file name, I ..

Read more