ruby

How do I validate certain fields with rails devise on registration only

拈花ヽ惹草 提交于 2021-02-19 04:06:55
问题 I have a set of custom fields attached to a devise model called Entrant. I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area. How do I achieve this? I am using rails 4.2 and ruby 2.1 回答1: You can simply specify validations on actions, that is: validates :name, presence: true, on: :create # which won't validate presence of name on update

How do I validate certain fields with rails devise on registration only

让人想犯罪 __ 提交于 2021-02-19 04:04:31
问题 I have a set of custom fields attached to a devise model called Entrant. I have two forms, one for registration form (three fields) and one which sits in the account area (12 fields). Most of the custom fields area required but only within the form the sits in the account area. How do I achieve this? I am using rails 4.2 and ruby 2.1 回答1: You can simply specify validations on actions, that is: validates :name, presence: true, on: :create # which won't validate presence of name on update

Is it possible to extend a class by using a string as a module ? - Ruby 2.7.1

不打扰是莪最后的温柔 提交于 2021-02-19 03:54:05
问题 I am doing some tests with Ruby 2.7.1 on FreeBSD 12.1. I know how to extend a class with module with for instance this : class Myclass def mymethod extend Mymodule end end But is it possible to obtain the same result with something that looks like this : class Myclass def mymethod var = "Mymodule" extend var end end If I do this like that, I off-course obtain an error, since extend is pointing to a string and not a module. Here are some explanations - it would be useful in the following

How to uninstall any application using python or (and) ruby

一世执手 提交于 2021-02-19 03:52:14
问题 I didn't find any helpful topics over the webs by this question. These all about how to uninstall python or uninstall ruby but there are no information about the #{TOPIC}. The main problem is that I used other interesting answers to try to uninstall an application using PowerShell script but all that didn't help me because that script with several variants of -Query "query" never finds my application even by unrigorous mask like '%APPL_NAME%' or by version number. Seems like table Win32

Rails: rake db:migrate *very* slow on Oracle

泄露秘密 提交于 2021-02-19 03:22:32
问题 I'm using rails with the oracleenhanced adaptor to create a new interface for a legacy application. Database migrations work successfully, but take an incredibly long amount of time before rake finishes. The database changes happen pretty quickly (1 or 2 seconds), but the db/schema.db dump takes over an hour to complete. (See example migration below.) It's a relatively large schema (about 150 tables), but I'm sure it shouldn't be taking this long to dump out each table description. Is there

Convert a unicode string to characters in Ruby?

时光怂恿深爱的人放手 提交于 2021-02-19 03:19:16
问题 I have the following string: l\u0092issue My question is how to convert it to utf8 characters ? I have tried that 1.9.3p484 :024 > "l\u0092issue".encode('utf-8') => "l\u0092issue" 回答1: You seem to have got your encodings into a bit of a mix up. If you haven’t already, you should first read Joel Spolsky’s article The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) which provides a good introduction into this type of

Convert a unicode string to characters in Ruby?

柔情痞子 提交于 2021-02-19 03:19:04
问题 I have the following string: l\u0092issue My question is how to convert it to utf8 characters ? I have tried that 1.9.3p484 :024 > "l\u0092issue".encode('utf-8') => "l\u0092issue" 回答1: You seem to have got your encodings into a bit of a mix up. If you haven’t already, you should first read Joel Spolsky’s article The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) which provides a good introduction into this type of

Convert a unicode string to characters in Ruby?

痞子三分冷 提交于 2021-02-19 03:18:45
问题 I have the following string: l\u0092issue My question is how to convert it to utf8 characters ? I have tried that 1.9.3p484 :024 > "l\u0092issue".encode('utf-8') => "l\u0092issue" 回答1: You seem to have got your encodings into a bit of a mix up. If you haven’t already, you should first read Joel Spolsky’s article The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) which provides a good introduction into this type of

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

GCC compilation error when installing Nokogiri

放肆的年华 提交于 2021-02-18 21:58:44
问题 I'm trying to run bundle install but I'm getting the Error while trying to Install Nokogiri 1.10.3 Here is the error message from mkmf.log . gcc -o conftest -I/home/chille/.rvm/rubies/ruby-2.5.1/include/ruby-2.5.0/x86_64-linux -I/home/chille/.rvm/rubies/ruby-2.5.1/include/ruby-2$ gcc: error: unrecognized command line option '-Wmisleading-indentation' gcc: error: unrecognized command line option '-Wimplicit-fallthrough=0' gcc: error: unrecognized command line option '-Wduplicated-cond' gcc: