Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Browsing all 4612 articles
Browse latest View live

Rails strange parameter added on POST request

I realized recently that a parameter is added when I try to create multiple items of my class User in a POST request.I have some permitted parameters:def user_params params.permit(:account_id, users:...

View Article


Rails: Form that sets up default values for an object?

Say I have an object that has some attributes with default values. I set up the default values for these attributes at a model level like so... after_initialize :set_defaults def set_defaults self.name...

View Article


How to automatically derive foreign key column names with polymorphic...

In my Ruby on Rails 7 application I have a large Account model with various has_many associations (most of them are left out for brevity here):class Account < ApplicationRecord has_one :address,...

View Article

Ruby on Rails 4: Pluck results to hash

How can I turn:Person.all.pluck(:id, :name)to[{id: 1, name: 'joe'}, {id: 2, name: 'martin'}]without having to .map every value (since when I add or remove from the .pluck I have to do he same with the...

View Article

skip validation in parent class

I have a few classes deriving from A.A does some validationIn the specific case of class B that inherits from A, I'd like to skip the validation.I'm using active interaction btwclass A <...

View Article


Grover.to_pdf: ReadableStream is not defined

I have a Rails app that is using the Grover Ruby gem, and it converts HTML to images perfectly well, but when I try to convert it to a PDF as shown below, I get an error saying the ReadableStream is...

View Article

Image may be NSFW.
Clik here to view.

Error running '__rvm_make -j8' in macos Monterey

I'm trying to install ruby 2.7.0 using RVM on MacOS(12.4: apple M2), but i'm getting below error and not able to install required ruby version. I have tried all the solutions available on internet...

View Article

Can't install ruby via rvm, Error running '__rvm_make -j4' on ubuntu 22.04

I have tried to install several versions of ruby (2.5.5, 2.6.6, 2.7.4, 3.0.0) and in all cases it has given the same error, of course with each version, in this example I only put the error for version...

View Article


Rails 7 error during application start - uninitialized constant...

I'm upgrading my rails app from 6.1 to 7.0 and i'm running into this runtime error:I do use the Authlogic gem, but the odd thing is i have no config/initializers file for Authlogic, and i can't find...

View Article


Access Rake Task Description from within Task

Within a rake task how does one query the description? Something that would give:desc "Populate DB"task populate: :environment do puts task.desc # "Populate DB"end

View Article

print function info without repeating or explicit calling a function in ruby

For debugging propose, in each method there is a print of the function namespace and its argumentmodule Test def self.foo(arg1, arg2) args = method(__method__).parameters.to_h { |p| [p.last,...

View Article

What is best way to set time in a Rails app form so that the time is the same...

I have a Rails 7 form where I enter in data to populate a database. I have a start_time and end_time in the form:<%= f.time_select :start_time, :value => Time.now.strftime('%I:%M %p') %><%=...

View Article

In Ruby, how do I find a value in an array of hashes?

I am trying to get a value in an array of hashes in Ruby. Given the following information below: # array_of_hash_objects will look something like this: # [ # { name: 'Ruby', is_my_favorite?: true }, #...

View Article


Check if a value exists before updating a column for a already existing...

Lets say I have table called Tokens, with columns: id, refresh_token, and token. refresh_token column should be unique. But we may have many refresh_token fields that are null. These null refresh_token...

View Article

Gem will not install sqlite3 despite sqlite3 being installed (Mac)

I'm trying to install Ruby (3.2.0) (and Rails [7.0.4]) on an Intel Mac (OS 12.6). I'm running into issues with sqlite3 — no surprise. My current error message is this:package configuration for...

View Article


How to configure Rubocop to skip counting log lines - Metrics/MethodLength...

Running RuboCop results in the following error$ rubocopRunning RuboCop...Offenses:C: Metrics/MethodLength: Method has too many lines. [25/10] (https://rubystyle.guide#short-methods)def example_method...

View Article

Steep "compatibility" warning

I'd like to have a Ruby class method return an instance on reading from a file. And I'd like that method to either take a string which is the path to the file, or an IO where the caller has opened the...

View Article


Rails 7 error during application start - Zeitwerk-related errors

I'm upgrading my rails app from 6.1 to 7.0 and i'm running into this runtime error:I do use the Authlogic gem, but the odd thing is i have no config/initializers file for Authlogic, and i can't find...

View Article

Rails form_with-helper: What is a :scope?

I'm currently reading the Ruby on Raily API-documentation. Specific the part about the form_with helper:...

View Article

money-rails - rounding up method

I have this method below: def formatted_from_net_per_day return unless object.price.available? formatted_price_for(object.price.from_price) endAs an example, it outputs:#<Money fractional:78571...

View Article
Browsing all 4612 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>