Most voted "ruby" questions
Ruby is a dynamic, interpreted, object-oriented, cross-platform, open-source language created by Yukihiro Matsumoto (Matz) in 1995. The [ruby] tag is for issues related to the Ruby language, including its syntax and its libraries. Specific questions about the Ruby on Rails structure should be marked with [ruby-on-Rails] and not [ruby].
Learn more…679 questions
Sort by count of
-
2
votes2
answers144
viewsHow to edit and create new record in DB? Ruby on Rails
I would like to know how I can make the following situation. I have 2 models Custo and Custo_Historico all the CRUD is already working. Only when I want to edit a cost it must always create a new…
-
2
votes1
answer79
viewsNested Attributes Rails Child model not saved
Good afternoon! I’m having a problem with storing models with nested Attributes. In the app, we have Customer, which has 1.. n Contacts, which in turn has 1.. n Telephones. I researched a lot before…
-
2
votes1
answer54
viewsSearch for random objects using conditions
I want to seek for example 10 random people of the same party I did as follows, but this selecting people from all parties, what can be done? = D class Pessoa < ActiveRecord::Base class <<…
-
2
votes1
answer2263
viewsBank Account Validation Rules
Where do I get official bank account validation rules and check digit? After a lot of searching on Google, I can only find rules from ten years ago and on forums, with no source reference. I heard…
-
2
votes2
answers514
viewsNested Attributes with Rails
I’m developing a system for study, which will allow the creation of a user. This user, in turn, will have an inventory, which will have several items. My question is how to save all these resources…
-
2
votes1
answer31
viewsClass variable in Java have the same behavior as in Ruby?
In Ruby a class variable that is modified by an object ends up modifying the value of all other objects instead of making a copy of that value. This also occurs in Java?
-
2
votes1
answer120
viewsRails 4 Error each_with_index when using activerecord-import
I’m trying to import an app into Rails 4 using Gem activerecord-import. When I try to execute the command: Detail.import( columns, values, :validate => false ,:timestamps => false ) I get a…
-
2
votes1
answer101
viewsHow to change an attribute in the bank via a button
I’m creating a small college project in Ruby on Rails and I came across a problem: I have a table called Person and another call Tools. People have many tools and every tool and owned by one person.…
-
2
votes1
answer122
viewsCreating a Ruby Commitment Schedule
I want to create a kind of routine that Intercale time interval Example: 8:00 to 12:00 with 30 Minutes interval A sample of the code class Appointment < ActiveRecord::Base has_many :schedules def…
-
2
votes1
answer84
viewsManipulate . txt file in Ruby and pupular BD?
I need to open a file. txt whatever has a string sequence separated by ";" and needs to be placed each ";" on a vector to then create a loop and insert it into the database. What do I have: require…
-
2
votes1
answer123
viewsCreate a list of ruby on Rails features
I’ve been trying for a few days but I haven’t been able to solve my problem. I need to create a list of features for an item and then list them all. I wish you could help me or give me some tutorial…
-
2
votes1
answer106
viewsHow to override "create" method from Vise?
Hello, I need to overwrite the "create" method from Windows to make a certain logic before saving the user. However I do not know the path of the stones to make such a change. I already googled but…
-
2
votes0
answers1271
viewsTest automation with Selenium Cucumber and Capybara
I’m starting to learn how to use a means for test automation in web applications. However, I came across a problem that I can’t solve and I can’t find anywhere (questions or documentation) that…
-
2
votes1
answer135
viewsDevise multiple login pages!
I am using Devise to perform my authentication. But I have 3 profile types, and created through the command rails g devise MODEL my users (Admim, dev and manager), but Devise created a login page…
-
2
votes1
answer118
viewsAccess level and hierarchy when checking checkboxes
Speak up, all right? Can you help me with something? I’ll explain: I enter the admin user and it shows all system permissions. As an example, suppose you have 10 (index, show, create, update, delete…
-
2
votes1
answer2041
viewsHEROKU connect to mysql database
I’m doing reverse engineering on a system, and what I want is to use the same database as the old system. But I am not able to connect the system database in production with this base. And because…
-
2
votes2
answers287
viewsChange Login [Gem Devise Ruby On Rails]
Gem Design creates a login system with email and password. How do I change the form of email login to a code, ie instead of the user login by email it enter with a number or name?
-
2
votes2
answers122
viewsString comparison
Problem : I have to get the object that displays the content in the English language ( lang == en ) But depending on the search performed the order of the languages comes completely different and I…
-
2
votes1
answer108
viewsProblem to select a specific object within a hash
Hello! Good morning. I have the following situation: In my Ruby code, there is a flower class(attributes: code(generated by a function with auto increment), name, value and category(this at ributo…
-
2
votes1
answer220
viewsService Discovery Eureka Netflix
I have an architecture SOA with two stacks different with java and other with ruby, I have a microservice using spring boot and other Rails, and I’m trying to set up a Discovery Service with Eureka…
-
2
votes1
answer1012
viewsRuby - Printing Zero as Decimal Place
I’m learning to code in Ruby, and to train, I use Uri Online Judge, where I solve exercises that are presented, code in some language that the platform accepts (in this case Ruby) and then send to…
-
2
votes1
answer152
viewsList has_many Relation Elements :through
I am creating an application and realized a has_many :through relation in my template. So far so good, worked smoothly, saved, edits and deletes. The problem is that I would like to list all the…
-
2
votes1
answer53
viewsWhy use Kernel#loop instead of Begin-end-while/until?
I’m making a Ruby repetition structure using the following structure: begin [código] end <while/until> [condição] But the Rubocop, which I use as a tool for linting, says I should use the…
-
2
votes1
answer747
viewsHow do I get the value of a hash in Rails?
I have some checkboxs inside a form in the view, which values are being sent to the controller by params to the index. obs. I’m sending the checkbox values from the view index to itself, I need the…
-
2
votes1
answer157
viewsMeasure time of a routine in Ruby
Is there a Ruby function to measure the time of a function? In python I use: ini = time.time() #função fim = time.time()
-
2
votes1
answer41
viewsRails - Relationship BD
I have a table user, where I have a mandatory field cidade, and I have a table contatos (that is belongs_to: user), but the form does not have the field cidade which is mandatory to user. How do I…
-
2
votes1
answer111
viewsWhy don’t booleans have a common class in Ruby?
Ruby doesn’t have a class Boolean. I realized that boolean objects are of specific classes depending on the value, see: true.class => TrueClass false.class => FalseClass Different from other…
-
2
votes2
answers87
viewsHow do Orms, like Active Record, generate SQL code?
I’d like to know how Orms in ruby transform a proc/lambda like this: { (id > 1) & (created_at < Time.now) } in something like " id > 1 and created_at < '2018-01-25' ".…
-
2
votes2
answers663
viewsRuby - comparison of values between a range or greater than, less than
I’m starting to study programming so, here’s a good beginner question. I took the test below to learn about case in Ruby, current_time = ARGV.first.to_i case current_time when 0..45 then puts('First…
-
2
votes2
answers116
viewsHow to update a CRUD with Scaffold?
I have a system with Ruby and a CRUD has been created via Scaffold and I would like to add some new fields. Because what I found on the internet was using the following command. rails generate…
-
2
votes1
answer99
viewsRuntime Error in Problem Using Recursion
I’m trying to solve the problem 1030 - Flavious Josephus Legend, from a challenge site. I send the code and says it has the Runtime error (Accesses an invalid memory or array has little space):…
-
2
votes2
answers124
viewsDoubt in array method each_with_index
When executing the method below it prints literally 0 x 2, 1 x 4. etc.. I need to find a solution to print only the result of the value product by the index. My current code: array = [2,4,6,8]…
-
2
votes2
answers252
viewsInterpolate variable name in ruby
Hello, I am developing a test automation where I have a variable that receives dynamic values, according to the test run. In the case of the contents of each element changes according to the…
-
2
votes0
answers127
viewsWhy is the "Rails new" command not creating the MVC skeleton?
Hello, I’m having a problem with Rails, when I run the command rails new nome_do_projeto in the terminal it should create the skeleton of folder MVC and the files containing the dependencies but the…
-
2
votes1
answer23
viewsHow to nest a route
Good afternoon, I have a service order and need to generate a report through it, this report needs to receive the service order number to save in the order_id column. I’m trying to make a nested…
-
1
votes2
answers109
viewsIs there a correct place to load native Ruby libraries when using Rails?
In certain functionality of my application, I need to use the "open-Uri" library, which is native to Ruby and does not have a library for Ruby on Rails. I’m using a require "open-uri" where I need…
-
1
votes1
answer171
views"Sqlite3::Sqlexception: no such table: main.Category" running rake db:migrate with Gem Acestry
I’m having a hard time using Gem Acestry in so far as it says: Add index to Migration: add_index [table], :ancestry (UP) / remove_index [table], :ancestry I’m creating a method called Category and…
-
1
votes2
answers118
viewsDeploy with Capistrano - Comando su
I’m using Capistrano to deploy on Amazon. Capistrano + Unicorn + Nginx + Ec2 When I go to deploy:Cold, it gives the following error: servers: ["ec2-xx-xxx-xx-xx.sa-east-1.compute.amazonaws.com"]…
-
1
votes1
answer299
viewsCreating projects in Ruby on Rails
I need to create a system that will be the following: A common user view page that will access the site with a login and password for your area A page where a company X will check its registered…
-
1
votes1
answer65
viewsWrite to ruby-on-Rails 3.2
Following the tutorial of railscast to add an image of the site Ravatar I found a lagged information with the updates of Rails. The code to create a default image in case of absence of registration…
-
1
votes1
answer86
viewsHow to test a Singleton class in Ruby?
I’m using require "Singleton" to make a certain class only be instantiated once. However, when running rspec tests, I get the following error: Nomethoderror: private method `new' called for…
-
1
votes1
answer419
viewsRuby on Rails: Rake aborted!
I’m starting in the world of Rails through the book Ruby on Rails - Put your web app on track. After creating a module "users" the guide informs us to add in the migration the following command…
-
1
votes1
answer138
viewsDo not use hidden_field fields in nested forms
I wonder if there’s a better way to work with nested attributes without having to send the id of the parent object through the field hidden_field, I find it unsafe to leave it to the page.…
-
1
votes1
answer1134
viewsHow to calculate the difference between two different hours in milliseconds?
How to calculate in milliseconds the time of an action in ruby? I’m doing it this way: start_time = Time.now I run a certain code that takes a few milliseconds end_time = (Time.now - start_time) And…
rubyasked 10 years, 11 months ago Fábio Jansen 82 -
1
votes1
answer149
viewsDoes the use of Engines in Rails 4 work the same way as in Rails 3.x?
Through several searches in the last few days regarding modularization of applications with Rails, I found vast material regarding Engines in Rails 3.x, but practically nothing referring to Rails 4.…
-
1
votes1
answer74
viewsHow to create routes, which accepts only allowed values?
How do I make :status accept only allowed values? # routes.rb get '/para_:status(/:opcao1)(/:opcao2)', to: 'search#index', :as => :search Currently :status accepts anything I submit. I wish…
-
1
votes0
answers156
viewsrespond_to show errors with relationships
My question is only about the architecture of how to return the error to view. Follow the example below: class Pessoa < ActiveRecord::Base belongs_to :responsavel, class_name: 'Pessoa',…
-
1
votes2
answers1254
viewsModel validation when update_attributes in Rails
I want to know how to validate my model for when @model.update_attributes(params) in my controller is called to return a possible error or false that seems to be the default returned by…
-
1
votes1
answer115
viewsHow to redirect to the application folder?
Use the ROR with the Nginx. How do I stop what the nginx redirect to the application folder? Instead of the folder /public.
-
1
votes1
answer227
viewsBest way to return data entered by a select of constants
I have a model Usuario and for him I have two constants that define a type for him. To pass this information to a select I have a method types that returns a Array. Ex: #models/Usuario.rb class…