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
-
1
votes1
answer55
viewsNew fields stay nil, what to do?
I’m deploying token and authentication, I’m using JWT and Devise, I’m having a problem with Devise, I don’t want to use email for authentication, I want to use a license plate, so I read the Devise…
-
1
votes1
answer84
viewsRelationship Through Many-To-Many Activerecord
I have the following configuration in Rails: Company has_many :company_products has_many :products, :through => :company_products Product has_many :company_products has_many :companies, :through…
-
1
votes1
answer1373
viewsText area with image
Hi, I’m going to make a form and I don’t know how to include an image within the text area, something like that. TEXT TEXT IMAGE TEXT Something to include user know? How is done here in stack…
-
1
votes0
answers51
viewsrqrcode_png Rails controller - Passing the string contained in the database by parameter
How do I pass the value that is in the field "codigo" of table "mesas" to the space Below "VALOR_STRING_BANCO"? How do I pass the value found in the field "codigo" table "mesas" into the space below…
-
1
votes1
answer48
viewsI would like to create an object equal to a query in the database
I would like to create an object with the fields equal to the query of Activerecord, however, with the fields pre-filled or blank, so that they are called in the same way in the other file... To…
-
1
votes1
answer345
viewsMetaprogramming with ruby, methods with SELF
good evening... I come from other languages somewhat different to Ruby, such as C/C++ , JAVA... And I got a little lost trying to understand the difference between the following methods: Class teste…
-
1
votes2
answers3880
viewsWhat is the unless command for in Ruby
Can anyone explain how this command works unless in Ruby? ruby_is_ugly = false puts "Ruby não é feio!" unless ruby_is_ugly Got out "Ruby não é feio!"…
-
1
votes2
answers743
viewsRead file and search word
I’m riding a script that will open a text file, play the words in a array, and then capture the word content, so far so good I can get the word content, but I need to go through all the array and if…
-
1
votes1
answer329
viewsHow could I add an ICONE inside a SELECT in HAML
Hello, I would like to add icons (from source, like bootstrap for example) inside a select field in HAML, at first I am doing so, would that be possible? I thought about using the bootstrap…
-
1
votes2
answers679
viewsRename column with Rails using Migration
I created a Migration to rename a column and only get the error; Undefined method `to_sym' for nil:Nilclass == 20161001182840 RenameColumnPasswordInUsersPasswordToPasswordDigest: migrating --…
-
1
votes1
answer103
viewsCheck records for the same month
I’m having trouble searching the sqlite3 database, records for a specific month, I searched the internet but I couldn’t find anything that could help me. I have an Account template that has…
-
1
votes1
answer21
viewsRspec - Feature test failing because elements are not rendered in test execution
I have a test Feature failing because the moment it runs some HTML elements (<li data-podcast>) not yet rendered. Does anyone know how to fix it? RSpec.describe 'Podcasts List', type: :feature…
-
1
votes2
answers421
viewsHow to send form_tag variables to javascript function? Rails
I am new to web programming and Rails and have the following question: I have a view that displays a food list and a field to fill with the amount of grams I want from each food. I’d like to exhibit…
-
1
votes1
answer188
viewsIs it mandatory to use belongs_to in Activerecord?
It is mandatory that in order to have an association between two models, I have belongs_to and has_one? Or it is possible to use only has_one/has_many between the two models, when not necessarily…
-
1
votes1
answer714
viewsCSV In Ruby - Doubt
Good afternoon guys, I’m having a little trouble understanding how Ruby works with csv, I need to read a file and import the data from that file into a variable I have a file called given.txt like…
-
1
votes1
answer116
viewssyntax error, Unexpected ( Arg, expecting end-of-input )
I came across this syntax error: syntax error, Unexpected ( Arg, expecting end-of-input ) larguraDaLinha = 40 str = '--> text <--' puts str.ljust larguraDaLinha puts str.center larguraDaLinha…
-
1
votes2
answers66
viewsSymbols on the Rails
After creating a template in Rails it is possible to change the created Symbol? For example I created a template called transaction, Rails creates plural transaction but I would like to change this…
-
1
votes1
answer139
viewsOperator and Ruby
I would like that code to take two numbers and show the numbers divisible by the first, the second and the two. However I could not make the use of AND for this case, because the div_pelos2 array…
rubyasked 7 years, 3 months ago vinicius martins 13 -
1
votes2
answers904
viewsAdd new fields in Migration ?
Hello I am working with Ruby On Rails, and for platform authentication I am using Gem 'Devise'. I came across a situation where I need to add new fields for user registration (Birthday date, gender,…
-
1
votes0
answers69
views" xed" Followed by "t" on UTF-8
I have a Rails application and when I run or compile the Assets it gives the following error: "\ xED" followed by "t" on UTF-8 In my application.Rb I already have that key: config.encoding = "utf-8"…
-
1
votes1
answer326
viewsHow to change the values of a Hash?
I need a loop to change the values of this object { [ "Begin", "Dom" ] => 0, [ "Begin", "Seg" ] => 8, [ "Begin", "Ter" ] => 10, [ "Begin", "Qua" ] => 30, [ "Begin", "Qui" ] => 20, […
-
1
votes1
answer64
viewsRails - Undefined Method 'client' for 'Book'
Hello, I’m working with ruby on Rails and I’m having the error: 'Undefined method', as in the image The employee is working, and if I put only the book.cliente_id, it works. Follow the codes below:…
-
1
votes1
answer61
views -
1
votes1
answer434
viewsHow to convert an object to Boolean in Ruby?
Ruby objects have some methods for representation in another type, such as: to_s: convert to string to_a: convert to array to_i: convert to whole to_f: convert to float But there is no standard…
-
1
votes1
answer1100
viewsColumn-specific selection in an HTML table in JS
Hi! I’m an IT student and I’m learning about Rails. I have the following HTML table of a view: <p id="notice"><%= notice %></p> <h1>Produtos</h1> <table class="table…
-
1
votes2
answers47
viewsNull return of an object in the controller - RAILS
Hello! I have the following code snippet from a controller called Productoscontroller: def index @produtos = Produto.all end def gerarlog @produtos.each do |produto| File.open('produtosBD.yml', 'a')…
-
1
votes1
answer720
viewsHow to make a search field with form_tag in Rails?
Hello! Good afternoon, sir. I am a student of information systems and I am doing a small project where I need to place a form to search for the objects of the model Product that exist in the…
-
1
votes3
answers169
viewscheck if you have a comma and delete a comma if you have it in the string by Ruby
hi how do I delete to check if the last word of the variable with string is comma and if this is how do I delete this comma at the end of the variable string type test = "my name is Neymar," then…
rubyasked 6 years, 9 months ago Francisco de Freitas 11 -
1
votes1
answer178
viewsRuby syntax error: Unexpected tCONSTANT, expecting keyword_end
When creating tables I used camelcase to create columns, but using Ruby on Rails to generate hash, when relating the two tables appears error message Code: @testes = Teste.find_by_sql( " SELECT *…
-
1
votes1
answer152
viewsRor error: Undefined method `[]' for nil:Nilclass -> Sitename::Home#index
This application was made through the following Bootstrap template: https://blackrockdigital.github.io/startbootstrap-business-casual/ In my case, after I have made all the changes and adaptations,…
-
1
votes1
answer507
viewsPass date by Ruby on Rails parameter
I’m trying to pass a date clicked as a parameter in order to load another view and I can’t. The idea is to list all bookings made on the selected day. Controller class ReservasController <…
-
1
votes1
answer89
viewsInheritance in Rails
I’m starting in the area, I have the following scenario in my back end done in Rails: I want to implement a parent class: Equipment: PK ID Brand ... And some child classes Printer: ID_EQUIPAMENTO PK…
-
1
votes1
answer138
viewsHow to generate sequential number automatically in Rails?
I am developing a form for registration in a selection process and after the user submit the registration data I would like to generate the registration number in the following format: 00012018. I…
-
1
votes1
answer42
viewsRetrieve field with Join in RUBY/Ror view
I have a big doubt, I’m a beginner in Ruby, and I’m not able to print the value of a field in my view, the result is this. My Model: class Pedido < ActiveRecord::Base has_many :produtos scope…
-
1
votes0
answers33
viewsWrite PC screen to Ruby
I need to create a Cucumber report with video and for that I need to know if there is a Ruby Gem that saves the PC screen.
-
1
votes2
answers187
viewsRuby syntax
What happens in this part here? def permut(vet) return [vet] if vet.size < 2 perm = [] vet.each{ |e| permut(vet - [e]).each{|p| perm << ([e] + p) } } perm end The first lines I understand,…
-
1
votes1
answer243
viewsRuby test Capybara encoding UTF-8 does not work
I created a new test project, using Ruby and Capybara for studies and I don’t understand why it’s not working. I have a very similar project on another PC, same configuration, the difference that…
-
1
votes1
answer749
viewsError: no implicit Conversion of Integer into String (Typeerror)
I chose the ruby language to learn how to program but I’m stuck in the following exercise: Write a program that asks for a person’s favorite number. Add one to the number, and suggest the result as…
rubyasked 7 years, 4 months ago user90660 -
1
votes1
answer243
viewsAssertion with the Rspec
I use the Cucumber + Capybara + Ruby framework and I am unable to make an assertion using the "expect" method. I need for example to validate four messages returned in body, but it displays error:…
-
1
votes0
answers46
viewsHow to use senitize_sql_like together with ilike
I’m having trouble using the senitize_sql_like, along with the ilike. When I use it, the query is not returning the expected value, it follows the implementation used: scope :brand_name_by_content,…
-
1
votes5
answers988
viewsError Split by 0
Hello I would like a help, I’m starting with language and I’m having some doubts, What I want in my code is that the division calculation is not divided by zero. The moment I enter the value of Y =…
-
1
votes1
answer70
viewsDo programs written in Ruby work on both Windows and Linux?
It is a doubt that I have regarding this programming language. The Java, for example, has no distinction of SO’s, because it has something like a ONLY internal, so it does not need a port specific…
-
1
votes1
answer71
viewsHow do I validate if a phrase containing accented words was displayed on the screen?
I am using Calabash-Android to perform automated tests and I want to know how I can validate if a phrase containing accented words was displayed on the screen. file.Feature # language: pt #…
-
1
votes1
answer75
viewsUndefined method in Ruby
I’m trying to make a relationship between two tables in Ruby, where I use the student and grades but when I go to localhost:3000/Students/1/Notes it causes me the error my notes_controller.Rb: class…
-
1
votes1
answer138
viewsRuby on Rails Sqlite3::Busyexception: database is locked: INSERT INTO
Hello, I am facing a problem with Sqlite3. When I run the code: user = SystemUser.new(email: "[email protected]", password: "marcos123") user.profile = Profile.new(first_name: "Marcos") user.save…
-
1
votes2
answers3115
viewsError installing Gem pg
I’m making that mistake when I turn the bundle install "An error occurred while Installing pg (0.21.0), and Bundler cannot continue. Make sure that `Gem install pg -v '0.21.0'` succeeds before…
-
1
votes1
answer170
viewsHow to use a method that is within a class and sums two numbers in Ruby
class Soma def somar(num1, num2) @num1 = num1 @num2 = num2 result = num1 + num2 puts "O resultado é #{result}" end end summing = sum.new (1, 2) I can’t understand why the following code doesn’t…
-
1
votes1
answer43
viewsArgue when calling function
I’m trying to run my code below: class ProdutItem attr_reader :price_unit, :x_item, :price_promo def initialize(price_unit: , x_item: 1, price_promo: price_unit) @price_unit = price_unit @x_item =…
-
1
votes1
answer109
viewsDisplay higher word frequency per line and calculate number of words per line
I have the following text and I have to display the words that appear most frequently per line and calculate the amount of words each line This is a really really really cool experiment really Cute…
-
1
votes2
answers51
viewsHow to simplify the process of classifying a value-based hash
Oops, I’m new to the site, and I’m new to Ruby. My question is: Is there a more efficient way to classify a hash according to the values? I did the code below, but I’m sure it’s not the most…