Posts by Luiz Carvalho • 3,644 points
110 posts
-
0
votes1
answer18
viewsQ: Assign the return of a method to a variable only if it is not nil
I wonder if there is a more ruby-like way to assign the return of a method to a variable only if it is not nil. An example code of how it would work in, say, an ugly way. def meu_metodo(valor) valor…
rubyasked Luiz Carvalho 3,644 -
0
votes0
answers34
viewsQ: Python NLTK does not correctly classify my text even though show_most_informative_features looks okay
Talk guys, I’m learning to mess with Python’s NLTK for a course, using the teacher’s example base, everything works fine, but when using a base of its own, something strange is happening and as I…
-
1
votes2
answers252
viewsA: Interpolate variable name in ruby
Welcome. There are several possibilities for you to do this, the one that is closest to what you are wanting to do is using the method send. I took the liberty of modifying your code a little to…
-
4
votes1
answer179
viewsA: How to work with GIT correctly?
The right way is a little relative, but I’ll show you how it’s been working with our team, maybe I can give you an idea. The branches of Hotfix are very similar to branches releases (branches that…
gitanswered Luiz Carvalho 3,644 -
0
votes1
answer218
viewsQ: Botpress installed one version, displaying the other at the start of the application
I’m trying to run version 10 (develop/x) of botpress, but every time I give start he displays the version 1.1.13 root@3900662b3eb1:/bot# bp start 18:49:25 - info: Starting botpress version 1.1.13…
-
0
votes1
answer23
viewsA: System of notes [params]
The error occurs because the model is waiting to receive an object Professional for your attribute .professional, but is receiving a String, which I believe to be the id that collection_select, try…
-
1
votes1
answer152
viewsA: Ror - Get controller Strong files inside the Application Controller
The best way I know how to do this is by using Gem Paper Trail, it is extremely dynamic and effective for this type of solution. I use it a lot in my projects for audit, versioning and recovering…
-
1
votes1
answer747
viewsA: How do I get the value of a hash in Rails?
You’re right, the method you seek is keys or values, example: {"2m"=>"1", "2"=>"2", "3m"=>"3"}.keys => ["2m", "2", "3m"] {"2m"=>"1", "2"=>"2", "3m"=>"3"}.values => ["1", "2",…
-
1
votes1
answer720
viewsA: How to make a search field with form_tag in Rails?
Hello, in your form you are putting produtos_path which refers to the Productoscontroller#index of your application. So that you your action getbusca you need to create this route and add it to your…
-
1
votes1
answer135
viewsA: Devise multiple login pages!
One strategy I use is to create a model User (responsible for authentication) and a model Profile which contains the profile data. Then you make a relationship between User has_one Profile and in…
-
1
votes1
answer106
viewsA: How to override "create" method from Vise?
Hello, In his RegistrationsController extending from Devise::RegistrationsController the envelope of create may be the following: def create super #sua lógica resource.save end I hope it helped.…
-
1
votes1
answer105
viewsA: route problems in ruby on Rails
Your route is ok. The problem appears to be in the controller, either it has not been set or it is with different nomenclature. Check your controller name and correct on your route. If you have…
ruby-on-railsanswered Luiz Carvalho 3,644 -
2
votes1
answer66
viewsA: Ruby on Rails web server problem
Hello. Make sure you are in the correct directory. It is a very common mistake to create a project rails new nome_do_projeto and then give rails s, but you’re out of the project directory. Then you…
ruby-on-railsanswered Luiz Carvalho 3,644 -
1
votes1
answer64
viewsA: Rails - Undefined Method 'client' for 'Book'
Change in your model Book the relationship of clientes for cliente class Livro < ApplicationRecord belongs_to :departamento belongs_to :funcionario, optional: true belongs_to :cliente, optional:…
-
0
votes2
answers14
viewsA: How to set values for config’s of my Handler in tests?
In rspec for the set of settings set for a Lita Handler can be done using registry. For example, in my case, my Handler calls dpeauth, to set these 3 configuration variables we can do so:…
-
0
votes2
answers14
viewsQ: How to set values for config’s of my Handler in tests?
My Handler has 4 configuration variables: config :base_url config :details_path config :create_path config :token I know them and my lita_config file, but to test my Handler, I need to set values…
-
0
votes1
answer19
viewsA: Addition of Array to a Hash during a loop does not persist the data until the end
It was enough to replace result = Hash.new([]) for result = Hash.new { |hash, key| hash[key] = [] }
rubyanswered Luiz Carvalho 3,644 -
0
votes1
answer19
viewsQ: Addition of Array to a Hash during a loop does not persist the data until the end
I had to come to you for help because I cannot see where I am wrong, certainly a nonsense. I am reading a csv and structuring this data into a Hash, where I have a header as key and a array of…
rubyasked Luiz Carvalho 3,644 -
2
votes1
answer1012
viewsA: Ruby - Printing Zero as Decimal Place
You can exit the floating point, try: puts "R$ %0.02f\n" % s.round(2) instead of puts "R$ #{s.round 2}\n" Result for me was ok, if I understood your question correctly: 4520.00 R$ 355.60 Good luck.…
rubyanswered Luiz Carvalho 3,644 -
1
votes1
answer744
viewsA: Someone knows how to solve this problem: cannot load such file -- rubygems.Rb (Loaderror)
If you are using RVM try: rvm fix-permissions rvm reinstall VERSÃO_DO_SEU_RUBY If you don’t try: gem install rubygems-update update_rubygems…
-
2
votes3
answers817
viewsA: How to simplify the translation call on i18n?
Like the ActiveRecord is who validates he already has his call hierarchy in the I18n, that is to follow your convention, as you have already demonstrated in your question. To change this behavior…
ruby-on-railsanswered Luiz Carvalho 3,644 -
0
votes1
answer95
viewsQ: How to mock a nonexistent class with Rspec Mock
I’m creating a lib that will use a model pattern of Rails, only that for the development of this lib I need to test without the presence of this model. So think about mocking (I’m using Gem…
-
1
votes1
answer788
viewsA: Redirect to another action from another controller in Rails
I see two ways to solve your problem, it will depend on the structure of your project. The first would be to render the other action, so you can use its variable @animal (...) else @animal =…
-
1
votes1
answer126
viewsA: How to change the layout of Replykeyboardmarkup/Quick Reply in api.ai for Telegram?
I did, to do this I had to stop using Quick Reply and used the Custom Payload which allows you to inform the custom response json just like in the documentation of the platform you are using. As in…
-
0
votes1
answer126
viewsQ: How to change the layout of Replykeyboardmarkup/Quick Reply in api.ai for Telegram?
ai for creating a bot, when using the service’s Quick reply the keyboard layout (Replykeyboardmarkup) in Telegram is vertical, thus cutting all messages: I saw that in the documentation dos Telegram…
-
0
votes1
answer279
viewsA: Nameserve: Undefined method `send_data' for Clonedatabase:Class
Hi @Ruan, I don’t think you’re finding it because send_data is an instance method not? and you are wanting to use it within a class method. Try to remove the self of his method make_clone and in his…
-
1
votes2
answers187
viewsA: Counter on model
Have you tried instead of <%= f.count %> use <%= @carro.count %> ?
-
2
votes2
answers176
viewsA: How to select record by position
take actually takes the first 3 records (uses LIMIT for that) Ex: Person.take(3) would generate an sql: SELECT "usuarios".* FROM "usuarios" LIMIT 3 For few records something like the solution below,…
-
0
votes1
answer22
viewsA: Assign ID at time of creation
I believe that in your case you can use the concept of Nested Resources. Basically in his routes.rb you will do something like: resources :blogs do resources :posts end This will create routes like:…
ruby-on-railsanswered Luiz Carvalho 3,644 -
2
votes2
answers992
viewsA: How to update Gem in windows?
When I had this problem I solved using this tutorial, but nowadays for Windows I prefer to use Jruby, let alone headaches.…
-
0
votes1
answer157
viewsA: Create an object with strong Ruby on Rails parameters
You really won’t need to stop Strong in this case. I believe only changing the new to the create will solve your problem in your action.
-
1
votes1
answer240
viewsA: error handling, Rails 4
You’re not carrying the @disciplinas in the create. As it gives some validation error it tries to render again the view, but @disciplinas is empty. Load it like you must have done in action new…
-
0
votes1
answer20
viewsA: property Prompt is not working
You need to put the prompt within the hash of html_options, try as follows: <div class="field col-xs-3"> <%= f.label :modelo_id %> <%= f.select :modelo_id, options_for_select(…
-
1
votes1
answer123
viewsA: Select sex with Enum
If you want to add one prompt in select, just add this option in f.select, as follows: <%= f.select :sexo, Grupo.sexes_for_select, prompt: 'Selecionar sexo' %>…
-
2
votes3
answers494
viewsA: Installing ruby with rbenv
Robson, the ideal is for you to remove first to protect yourself from any conflict issues between Ruby versions. Leave everything to rbev. sudo apt-get purge ruby rubygems…
-
0
votes1
answer233
viewsA: How to implement attribute login from another table with Devise in Rails 4?
The Devise documentation has an example of how to solve this. It uses username or e-mail to exemplify, but can easily adapt to CPF or e-mail. Take a look here it’s a bit of a laborious process, so I…
-
2
votes1
answer174
viewsA: Doubt about float field query (ruby on Rails with mysql)
The Rails works with point fields flutuante de modo transparent, so you don’t need to make this conversion explicit. A detail, for migrations from Rails pontos flutuantes are worked in a generic way…
-
2
votes1
answer54
viewsA: Perform searches using repetitions
So Erasmus, this type of consultation will not accumulate, as it is the normal behavior of any query: Search for new records. That is you will have to do this accumulation manually, let’s try one of…
-
1
votes1
answer35
viewsA: store the formatted value of my created_at date in the ID
how to do this is using callbacks , where in the object creation action (after_create), you will set this value to the field shoe_id, so for example: class Shoe < ActiveRecord::Base after_create…
-
1
votes2
answers218
viewsA: Add new field to the bank with Rails
@Rafael, the problem is that you are not passing client_id as a Contents attribute (using f ) in your form, in cases such as yours, I particularly like to use the collection_select, would look…
-
2
votes3
answers122
viewsA: View related data during Iteration
Hello @Rafael, Problem is that in the log you searched on the console client exists, but during the loop one of the records does not have a client related generating error. There are several ways to…
ruby-on-railsanswered Luiz Carvalho 3,644 -
3
votes1
answer54
viewsA: Search for random objects using conditions
Hello, just pass the rand() as order. Example: class Pessoa < ActiveRecord::Base class << self def filtra_pessoas() Pessoa.where(partido: "sem partido").order('rand()').first(10) end end…
-
0
votes2
answers280
viewsA: List random objects
You can make a Scope to bring these cars in randomly. It looks something like this: class Pessoa < ActiveRecord::Base has_many :carros end class Carro < ActiveRecord::Base belongs_to :pessoa…
-
2
votes2
answers398
viewsA: Why not create a Ruby on Rails distribution that works well on Windows?
Hello, good if we were to expose all the problems of creating something that runs well on all platforms we would write a beautiful article, instead we will focus on solutions. A great difficulty in…
-
0
votes1
answer84
viewsA: Relationship Through Many-To-Many Activerecord
In a relationship has_many throught you can use the uniq to ensure that duplicated relationships will not be created. It would look something like: Company has_many :company_products has_many…
-
1
votes1
answer196
viewsA: How to run shell script to restart server by application
In order for you to run a script disconnected from the process that started it, you need to send it to the background. For example if you are running: sh . /meuscript.sh just add & in the…
-
1
votes1
answer35
viewsA: Ruby on Rails Ordering and Relationship Parents Kids
Whereas there is a relationship has_many/belongs_to between the model Pai and the model Filho, you can do the following: Filho.includes('pai').order('pais.idade DESC') All right, all children will…
ruby-on-railsanswered Luiz Carvalho 3,644 -
1
votes2
answers55
viewsA: How to compare hash coming from JSON on RAILS
Hello, I suggest you take a look at this Railscast that talks exactly about token authentication.…
-
0
votes2
answers177
viewsA: Failed to insert Gem mysql in Linux Manjaro
Hello you need to install native build libraries from MySQL sudo apt-get install libmysqlclient-dev If you have not installed, install also the build-essential sudo apt-get install build-essential…
-
2
votes1
answer84
viewsA: Manipulate . txt file in Ruby and pupular BD?
You were well on the right track, missed only the cat jump I will use an input file for demo txt groups. 'Administradores'; 'adm'; true 'Redatores'; 'red'; false 'Editores'; 'edt'; false 'Leitores';…