Facing some issues with ActionCable
Currently trying to implement a website with Ruby as my backend and React as my frontend. Checked that my frontend is already subscribed to the correct channel. When a new Model (TourGuidePackage) is...
View ArticleDependabot for big Rails project times out
Running dependabot on Github on our large Rails project times out (the job is killed after 55 minutes).Our Gemfile has 176 gems, 151 which use the ~> operator, so Dependabot will try to upgrade...
View ArticleHow to programmatically get inner body(code) of a ruby method [duplicate]
Is there anyway to programmatically return the contents of a ruby method as a string? For example something like this?class Foo def foo_method some_code = "goes here" endendputs...
View ArticleBest practice for similar repeated queries using ActiveRecord
I have a couple simple queries and I'm not sure what the best practice is.I've written them in 2 ways which produce the same result. Which is preferred? Or is there a third, better way?More...
View ArticleHow to remove square brackets (only) from an array? [duplicate]
I have an array stored in a constant like this:FIELDS = ["first_name", "last_name", "occupation"]I need to remove the square brackets only, it will look like this:"first_name", "last_name",...
View ArticleCannot access value at 'user.email_activities'
I have models/user.rb that has association with email_activities:class User . . has_many :email_activitiesendand models/email_activity.rb:class EmailActivity . . belongs_to :userendI am accessing the...
View ArticleChange button class if value true or false
I have two buttons with opposite states "Freeze" and "Unfreeze". When the database record is in a false state, I want to show the button "Freeze" below:<%= form.submit "Freeze", class: 'bg-blue-500...
View ArticleHow do I get my current ruby program to loop through three input options and...
I am attempting to get my current program to give the user three different input options and notify the user if they have attempted to use the same input option twice.My current code:prompt = "Do you...
View ArticleDisplay yes/no with content_tag helper by boolean
I am trying to display a badge pill that says 'Yes' or 'No' based on it's boolean value, using a content_tag rails helper.I currently have my helper method written out as def boolean_for(bool = false)...
View ArticleShould I use Class Methods or Instance Methods?
I am trying to understand what is the best approach for this calculator service. It will be called when there is a request coming in via API and return some data arranged in a table.Below you will find...
View ArticleRAILS - CHANGE FIELD OF ANOTHER TABLE - BOOLEAN
Good afternoon. I'm new to rails and I'm using google translate to post in English here, so sorry if it's not very readable.My question is, I have a User table, and a Setting table.They are related...
View ArticleSingle Backslash in Ruby String
I am using ruby 2.7.5. I am trying to get ^~\& assigned to a variable. I want string with only one backslash on it. I tried different things but none of them give me the desired result.attempt...
View ArticleChecking a condition before running multiple methods. Ruby on Rails
Lets say I have a class with hundreds of instance methods in it. Now I have the requirement to run each method only if a certain thing is detected. Also I want to run my detection algorithm once for...
View Articlesleep until condition is true in ruby
Is there any better way in Ruby to sleep until some condition is true ?loop do sleep(1) if ready_to_go break endend
View ArticleFormula for calculating user experience
I would like (without using a gem) to create a level and experience point system for my users.When creating his account, he starts level 0 with 0 experience points. To reach level 1 he will need 10...
View ArticleWhat is the difference between :id, id: and id in ruby?
I am trying to build a ruby on rails and graphQL app, and am working on a user update mutation. I have spent a long time trying to figure it out, and when I accidentally made a typo, it suddenly...
View ArticleI know how to reverse a string in ruby without .reverse, but is there a way...
I know how I can reverse a string in ruby without the reverse methoddef reverse(string)string.each_char.inject(""){|str, char| str.insert(0, char) }endputs reverse('hello world')but is there a way I...
View ArticleRails | Kaminari: how to limit max pages?
I'm using Kaminari gem for pagination.I have an exception when trying to run such code:Distributor.all.page(123123213213132113322)=> ActiveRecord::StatementInvalid (Mysql2::Error: You have an error...
View ArticleHow to create a delete link for a related object in Ruby on Rails?
So let's say I have Posts and Comments and the url for show is /posts/1/comments/1. I want to create a link to delete that comment in the comments controller destroy method. How do I do that?
View ArticleHow to get information on a process (not the current process)
Is there a Ruby module or class that gives information about a currently running process that is not the current process? For example, if I have pid 1234, I'd like to get information on the user of the...
View Article