Posts by Luiz Carvalho • 3,644 points
110 posts
-
0
votes1
answer206
viewsA: Printing on Ruby on Rails
Unfortunately there is no way to accomplish this using any application server side, except if you develop a client that runs locally on the user’s machine and receives this information by a…
-
0
votes3
answers295
viewsA: Display fields from a hash in the view
You can iterate on @results: <% @results.each do |result| %> <b>Produto:</b> <%= result['desc_produto'] %> <br/> <b>Cor:</b> <%= result['desc_cor'] %>…
-
0
votes1
answer33
viewsQ: Saving father and son if both are valid in Rails
I have two classes Protocolo and Movimentacoes, in the rescue of Protocolo I create a new Movimentação. class Protocolo < ActiveRecord::Base has_many :movimentacoes after_create…
ruby-on-railsasked Luiz Carvalho 3,644 -
0
votes2
answers440
viewsA: How to automate merge into git / github with hook or other tool?
With Jekyll If you were using Jekyll you could create a script with the following command: #!/bin/bash git push origin `git subtree split --prefix _site master 2> /dev/null`:gh-pages --force then…
-
1
votes2
answers440
viewsA: How to automate merge into git / github with hook or other tool?
Mirroring master code using Git Hooks In case you want to hook of push, rename the file pre-push.sample for pre-push and paste the following code: echo $DEPLOYING if [ -z "$DEPLOYING" ]; then echo…
-
1
votes4
answers1978
viewsA: Mask in Rails fields
How have you done the require in his application.js, make sure you did the require also of JQuery //= require maskedinput //= require jquery jQuery(function($){…
-
1
votes2
answers256
viewsA: Rails and Mysql - Data Types
The Rails uses ActiveRecord (ORM) to map all tables and attributes of them. So to use Rails without using external libraries, yes you will only be able to use the data offered by Rails. However you…
-
0
votes1
answer214
viewsA: Different Model type objects mapped from a single table
The ActiveRecord supports yes this type of inheritance. For this to work first we have to add a type attribute para the model Pessoa. Creation of this table would be something like this: rails g…
-
1
votes2
answers581
viewsA: Create New Method in Rails
Good I will consider that you already have Rails properly installed and configured on your machine. It is unclear whether your method is really a method of Model or a action (a method of…
ruby-on-railsanswered Luiz Carvalho 3,644 -
1
votes2
answers155
viewsA: Rails performing XHR request when loading pages
I think these requests that you are logging into your service are being carried out by Turbolinks(Added in version 4 of the framework), unfortunately it does not have Two Way databind, because its…
-
0
votes1
answer52
viewsA: When using puts exits only the address, and not the expected message
Hello I checked your code here and it worked: Instantiating the class class Livro attr_accessor :preco,:autor,:editora,:nome def initialize nome_livro, autor,_editora = nil, preco @nome = nome_livro…
rubyanswered Luiz Carvalho 3,644 -
3
votes2
answers3815
viewsA: Selenium WebDriver_ Access page without opening browser
Yes. Enough install Phantomjs. Then you change the webdrive from: driver = webdriver.Firefox() for: driver = webdriver.PhantomJS() The rest of the code I believe you will not need to change.…
-
0
votes1
answer73
viewsA: Function reference in Ruby Array
@Guigs said this is it, best is a Hash and :fitness is simply the access key to a position of that hash. I ran your code and for example the end result of best is…
-
0
votes1
answer27
viewsA: How to test custom Rails Validator
I resolved it that way: require 'rails_helper' describe StatusMappingValidator do let(:status_map) do { status_a: [:status_b], status_b: [:status_c], status_c: [:status_b, :status_a] } end…
-
1
votes1
answer27
viewsQ: How to test custom Rails Validator
Hello I have the following custom Validator class StatusMappingValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return nil if…
-
1
votes2
answers174
viewsA: How to send commands to the ruby interpreter from a Shell Script?
To execute a direct command in the Ruby interpreter use -e, in short your example would be: #!/bin/bash function generate_hash { # Enviar o argumento para o interpretador e obter o retorno. ruby -e…
-
0
votes3
answers122
viewsA: How to install rvm in Debian
Try to perform the following steps: Install some Debian prerequisites apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev…
-
4
votes1
answer102
viewsA: Doubt Relationship Rails
For what he described the correct modeling would be: In the model of Animal: class Animal < ActiveRecord::Base has_many :reproductions_as_father, class_name: 'Reproduction', foreign_key:…
-
0
votes2
answers69
viewsA: Gem not available
This is missing from Gem jquery-rails, try: sudo gem install jquery-rails
rubyanswered Luiz Carvalho 3,644 -
2
votes1
answer527
viewsA: Slideshow images with android
I use a very good call Androidimageslider Setup step 1 1 Gradle dependencies { compile "com.android.support:support-v4:+" compile 'com.squareup.picasso:picasso:2.3.2' compile…
-
2
votes1
answer70
viewsA: Error saving marked data in a query
From what I understood you during the creation of a quiz you’d like to add vehicles to him. It would be quite easy if you could create the quiz and then associate the vehicles, but from what I’ve…
ruby-on-railsanswered Luiz Carvalho 3,644 -
3
votes2
answers231
viewsA: Quick search for a string or part of it in an Array
I arrived at a very simple result using regular expression and index images.index{|s| s =~ /cha_bar/} or images.index{|s| s =~ /cha/} This will return to the position of String sought.…
rubyanswered Luiz Carvalho 3,644 -
4
votes2
answers231
viewsQ: Quick search for a string or part of it in an Array
I have the following array: images = %W( droido 7midias vigilantes sebrae_mei dpe_saed websat ferpamweb dpe_chronus dpe_plantao promocast lolitaface dpe_intranet cha_bar clinica_sorriso…
rubyasked Luiz Carvalho 3,644 -
3
votes2
answers179
viewsA: How do I redirect a page by clicking an option from a select by google Chrome?
Problem was that the ready was not closed, code fixed: $(document).ready(function(){ $("#select-native-fc").on('click', function(){ if($("#select-native-fc").val() == "ASM2") { alert('Teste'); } });…
-
0
votes2
answers144
viewsA: How to edit and create new record in DB? Ruby on Rails
One of the ways to do this type of operation is by using Callbacks and whenever a custo is saved, it will generate a new record of custo_historico. Whereas you have implemented a 1xN relationship…
-
1
votes2
answers911
viewsA: How to edit Devise Views?
To be able to edit Devise Views you will execute the following command: rails generate devise:views This will generate customizable views within your project, so you can change them however you…
-
0
votes1
answer52
viewsA: Testing with rspec - problems with stub and should
Try: helper = double helper.stub(current_user: current_user) Or: helper = double helper.stub(:current_user).and_return(current_user)
-
0
votes1
answer410
viewsA: Run Rails commands on the Ubuntu terminal
Two things can be done: Add to your archive ~/.profile or ~/.bashrc: [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" Or the most recommended way, for example in Gnome…
-
1
votes1
answer101
viewsA: How to change an attribute in the bank via a button
You can do an action on ToolsController, where you will pass the id of the tool, in this controller you perform the lending action. I suggest you instead of putting an attribute loan, put the…
-
0
votes1
answer126
viewsA: Multiple submits calling multiple methods in a single form
You can use the formaction <button type="submit" formaction="/reter">Reter</button> <button type="submit" formaction="/liberar">Liberar</button> Here it worked exceptionally…
-
0
votes1
answer108
viewsA: Error installing rvm switches
Probably his /etc/apt/sources.list is with broken repositories. Try: sudo apt-get install gawk libreadline6-dev libyaml-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison…
rubyanswered Luiz Carvalho 3,644 -
0
votes1
answer884
viewsA: How to make a multidimensional matrix read data entered by the user?
Hello, I tested your code, only one to_i was missing to convert the entire input, I do not know if this was your difficulty. I made some modifications to your code. tabuleiro = [[1, 2, 3], [4, 5,…
rubyanswered Luiz Carvalho 3,644 -
1
votes1
answer398
viewsA: Create system access levels
As you are using Rails, you can create these rules in Backend using Cancancan. Read the documentation for installation and configuration. All access rules are carried out in the file ability.rb, for…
-
1
votes2
answers426
viewsA: Extract a new array from an array - Ruby
We can simplify the code a little bit and leave more "ruby like" : [["CELULA", "LENNA", "JUL 01", "2015 12:00:00 AM", "N"], ["CELULA", "ARI", "JUL 01", "2015 12:00:00 AM", "P"]].map {|e| [e[1],…
-
2
votes2
answers1228
viewsA: Change date format in Rails form
Put in your config/application.rb Time::DATE_FORMATS[:default] = "%d/%m/%Y %H:%M" Date::DATE_FORMATS[:default] = "%d/%m/%Y" That the formatting of all system dates go to the Brazilian standard.…
-
0
votes1
answer186
viewsA: Saving information in bank and sending via post in Rails
Eduardo, in your controller take a look at the params variable, she is responsible for carrying the form information to your controller. In your controller use Model to save these. To save this same…
-
1
votes1
answer241
viewsA: Undefined method `chomp' for nil:Nilclass
In the following section you ask the user to enter the amount of element, but then try to iterate on a String (undefined methodeach' for "1":String (Nameserver)), primeiro que você precisa converter…
rubyanswered Luiz Carvalho 3,644 -
1
votes1
answer45
viewsA: Ruby doubt Apis
this link is for the core methods. To consult the extra Ruby methods the documentation itself already displays, but elsewhere. Follow the link. PS: includes the YAML documentation you quoted! Good…
-
1
votes1
answer54
viewsA: Fix HTML of a page using Ruby/Nokogiri
To reply was sent in the OR. Basically using the Gem Nokogumbo in conjunction with Nokogiri, where the HTML5 parse results in the same HTML correction used by Google Chrome! Works beautifully!…
rubyanswered Luiz Carvalho 3,644 -
1
votes1
answer54
viewsQ: Fix HTML of a page using Ruby/Nokogiri
I’m having a little difficulty consuming an HTML generated by a third party page, where HTML is missing some closing tags. For example: <div> <li> <div> <div>test test…
rubyasked Luiz Carvalho 3,644 -
0
votes1
answer109
viewsQ: Hash inside another Hash always returns empty if no key is used
Well I created a method to group all one user’s commits per month into one Hash: def calculate_month_ranking(commits) rank = Hash.new(Hash.new(0)) commits.each do |commit_yml| commit = YAML.load…
rubyasked Luiz Carvalho 3,644 -
2
votes2
answers624
viewsQ: Initializing instance variables in Activerecord
I’m having difficulty initializing instance variables in Rails, I need to use a variable in several methods, but this needs to be initialized beforehand, for example: class Test <…
-
2
votes1
answer525
viewsA: Add Facebook sdk 3.20.0 to Android Studio 0.9.2
try this solution: Download the Facebook SDK(https://developers.facebook.com/docs/android/) Unzip facebook-android-sdk-3.20 file. 0 In Android Studio perform the following operation: File…
-
8
votes1
answer4080
viewsA: How to make a switch in Ruby?
In this case Ruby uses the structure case...when case objeto when 1 puts "Seu número é 1" when 2..10 puts "Seu número está entre 2 e 10" when 11,13,17,19 puts "é um número primo entre 10 e 20" when…
-
5
votes1
answer839
viewsA: How to download videos from youtube and convert them to mp3 using ruby?
you can use the youtube-dl to do this, and using Ruby would be simple. system("youtube-dl -t --extract-audio --audio-format mp3 http://www.youtube.com/watch?v=#{id_do_video}") if you want to…
-
4
votes1
answer790
viewsQ: Dynamic calculations in Rails
I hope you can help me. I have a Rated who owns evaluations, have several calculations to determine whether or not it will pass an evaluation step. For example one of these calculations is…
-
1
votes1
answer209
viewsQ: Use of Nested Attributes with "has_many through" relationship table
I have the following problem, I have a relationship: class Servidor < ActiveRecord::Base has_many :lotacoes, :through=>:servidor_lotacoes has_many :servidor_lotacoes end class Lotacao <…
-
4
votes2
answers4403
viewsQ: Margin breaking layout in Bootstrap
I’m trying to make a Row with nested Rows but with a spacing between them, without the spacing the layout gets beauty, but when adding the margin the layout breaks! What I’m trying to do: The result…
-
1
votes1
answer227
viewsQ: Best 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…
-
0
votes1
answer176
viewsQ: Problems with multiple ajax forms on the same page
I’m having a strange problem when I put several forms on the same page (in the index case) all have the parameter remote: true created from a loop in my records. The problem is that only the first…