ruby-2.2

How to generate a unique random id for post in Ruby on Rails 4?

筅森魡賤 提交于 2020-01-06 19:56:49
问题 I want to produce unique post identifier for posts in my blogging application. Currently I am using SecureRandom.hex(10) for generating unique post identifier for my blogging site but I am not sure is it safe SecureRandom for this purpose. Is there any other way to do this? 回答1: From the Ruby doc: This library is an interface for secure random number generator which is suitable for generating session key in HTTP cookies, etc. I had similar problem, I used Digest library. Digest::MD5.hexdigest

Why does “instance.send(:initialize, *args, **kwargs, &block)” fail only from within Class#new?

我怕爱的太早我们不能终老 提交于 2019-12-25 03:32:52
问题 I've been stuck on this for quite a while now. Take a look at this: class SuperClass def self.new(*args, **kwargs, &block) i = allocate() # Extra instance setup code here i.send(:initialize, *args, **kwargs, &block) return i end end class Test < SuperClass def initialize puts "No args here" end end The class SuperClass basically "reimplements" the default new method so that some extra initialization can happen before initialize . Now, the following works just fine: t = Test.allocate t.send(

Rails and RSpec: Testing controllers with the same name in different namespace (module)

喜欢而已 提交于 2019-12-24 02:00:45
问题 I have rails 4.1.16 API application that is tested using RSpec 3.4.0, and I experience problems with testing classes called the same name in a different module. The structure is: app/controllers/bar/notifications_controller.rb class Bar::NotificationsController < ApiController ... end and controller with the same name in a different module: app/controllers/foo/bar/notifications_controller.rb module Foo class Bar::NotificationsController < ApiController ... end end The Foo is a new module and

Ruby regex to match only single digits in a comma-delimited string

泪湿孤枕 提交于 2019-12-13 02:33:44
问题 I am having input strings like: "1,7" "1,2,3, 8,10" "1, 4,5,7" I am trying to write a regex to match the above strings with following constraints are: it should match only single digits and that too in range of 1-7 the comma after a digit is optional for e.g. there can be a string "4" in which 4 should be matched a digit can be prefixed with whitespace, however it should be ignored I tried with following: ([1-7]),? but that matches consecutive digits like "55," in following input string and

Encrypting files for travis-ci on ruby-2.2.2 fails with “private method `load' called for Psych:Module”

纵饮孤独 提交于 2019-12-11 11:03:56
问题 I'm having trouble encrypting my database.yml for Travis CI. Based on their documentation, it appears you encrypt files with the travis encrypt-file command. I'm running on Ruby-2.2.2 and it's giving me some pretty cryptic error messages. travis encrypt-file config/database.yml --add And I get this error: private method `load' called for Psych:Module for a full error report, run travis report Here's the backtrace when I run travis report : $ travis report /Users/William.Jeffries/.rbenv

ActiveModelSerializers (0.10.0.rc3) an object's relation's relation is not generated with default FlattenJson adapter

…衆ロ難τιáo~ 提交于 2019-12-10 23:56:20
问题 Rails 5 Alpha version / Ruby 2.2.3 / active_model_serializers (0.10.0.rc3) ( henceforth referred as AMS ) GIT remote: https://github.com/rails/rails.git revision: 5217db2a7acb80b18475709018088535bdec6d30 GEM remote: https://rubygems.org/ specs: active_model_serializers (0.10.0.rc3) I already have a working API-only app utilizing Rabl-Rails to generate the JSON responses. I am working on making it ready to work with Rails 5 and as part of this evaluating Rails 5 inbuilt API features esp the

Ruby str.match(regex) returns MatchData containing only first matched item

霸气de小男生 提交于 2019-12-10 15:26:47
问题 Using Ruby 2.2 I have strings like following: Weekly on Tuesday and Friday Weekly on Monday, Wednesday and Saturday Monthly every 2 weeks on Monday To extract the days of week from above shown strings I have written following regex: /\b(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)\b/ When trying to use String#match instance method the match_data doesn't return all matches. For e.g. please refer the irb output shown below wherein when the string Weekly on Tuesday and Friday is

How to harden rails+webrick+https with insecure ciphers removed on Ruby 2.2

↘锁芯ラ 提交于 2019-12-08 06:30:03
问题 Updated: At first, my test code didn't adequately show ruby 2.4 sees the :SSLCiphers option whereas ruby 2.2 does not. I have edited the example code below to make that clear. Updated: Since my question failed to elicit any help from the community, I forged on ahead and two days later found the solution, which I have included below. I have a small Rails 3 application on Ruby 2.2 and Webrick that handles small loads and therefore does not need the complexity of a "real" web server. It has been

How to harden rails+webrick+https with insecure ciphers removed on Ruby 2.2

你。 提交于 2019-12-07 13:44:31
Updated: At first, my test code didn't adequately show ruby 2.4 sees the :SSLCiphers option whereas ruby 2.2 does not. I have edited the example code below to make that clear. Updated: Since my question failed to elicit any help from the community, I forged on ahead and two days later found the solution, which I have included below. I have a small Rails 3 application on Ruby 2.2 and Webrick that handles small loads and therefore does not need the complexity of a "real" web server. It has been patched to support https connections for secure logins, but by default, it accepts many old weak

ruby on rails AbstractController::Helpers::MissingHelperError: Missing helper file helpers//

ⅰ亾dé卋堺 提交于 2019-12-06 09:09:43
I just cloned a repository I was working on from another computer. When I try to do a database migration by running 'rake db:migrate' I get the following error: AbstractController::Helpers::MissingHelperError: Missing helper file helpers//users/psmith/projects/clie/projectlion/app/helpers/application_helper.rb_helper.rb I have already tried the top answer here: Rails: AbstractController::Helpers::MissingHelperError - Missing helper file application_helper.rb_helper.rb It says to do the following in the terminal: cd ~ mv projects projects1 mv projects1 projects I have also tried: sudo ln -s