Posts by Peoplee • 979 points
20 posts
-
1
votes1
answer2436
viewsA: Undefined method `+' for nil:Nilclass - Ruby error
In your class store.Rb the variable total is defined outside the method def to_s, soon it becomes inaccessible for instance methods. The correct code for it would be the following: class Store…
-
2
votes2
answers231
viewsA: Quick search for a string or part of it in an Array
You can also use the method Enumerable#detect (or Enumerable#find) and it will return the first element that returns true in block condition: images.find {|s| s =~ /lan/ } # => 'vigilantes' Or,…
-
2
votes1
answer86
viewsA: Register two separate models in one
How the relationship of courses and students is of the type has_many, you need to use the attribution curso_ids and aluno_ids, so your form would look like this: <div class="field"> <%=…
-
2
votes5
answers3336
viewsA: How to mix an array in Javascript?
Using as reference the underscorejs.com: Array.prototype.shuffle = function() { var set = this; var length = set.length; var shuffled = Array(length); for (var index = 0, rand; index < length;…
-
1
votes1
answer109
viewsA: Hash inside another Hash always returns empty if no key is used
In this case you are changing your hash fallback to keys that don’t exist (when you do: rank = Hash.new(Hash.new(0))). That is, whenever you try to access a key that does not exist in the rank you…
-
3
votes1
answer1086
viewsA: Manipulate . txt file and put it into a Ruby array
You can use the method readlines tweets = IO.readlines('filename.txt') puts tweets[0] # => "primeiro tweet" But if you want an array identical to the one you requested, do so: tweets =…
-
3
votes1
answer266
viewsA: Select non-empty field
You can use the expression CASE in select, for example: SELECT CASE WHEN imagem != '' THEN imagem WHEN flash != '' THEN flash WHEN codigo != '' THEN codigo ELSE NULL END AS val FROM publicidade…
-
1
votes1
answer109
viewsA: Using Strong Attributes with Rails 4 and has_one relationship
There are two problems in your code. The first is the name of the nested parameter of the model address down in the person_params. people_controller.Rb def person_params…
-
4
votes2
answers186
viewsA: Tools for working with Graphics
My suggestion is to use the d3js http://d3js.org/ It is very customizable and the examples gallery is great to help in the beginning https://github.com/mbostock/d3/wiki/Gallery…
-
3
votes3
answers353
viewsA: How can I split this INSERT into steps?
In PHP, regardless of the amount of records in the database: <? mysql_connect( ... ); $query = mysql_query("SELECT * FROM imagens1 t1 INNER JOIN imagens2 t2 ON t1.ID = t2.ID"); $num_rows =…
-
1
votes2
answers1596
viewsA: Cell with dynamic height in FPDF
When I needed something similar I used the method MultiCell of the FPDF. See the documentation here: http://www.fpdf.org/en/doc/multicell.htm Edit: I found this tutorial that can help…
-
0
votes3
answers855
views -
3
votes1
answer95
viewsA: Operation of file handling functions
PHP is written on top of C, so what these functions do is simply call for fopen(), fclose(), and other functions of stdio.h of C. So you can’t directly access a file in the file system without using…
-
17
votes3
answers317
viewsA: What are the most common problems and dangers when enabling `register_globals` in php?
With this option enabled it is possible for the user to define variables in his code at the time of the request, and therefore his code should be written with very carefully (which doesn’t happen…
-
2
votes2
answers281
viewsA: Save visitor IP in text file, but how not to save again if already there and how to read?
As people have already commented in the comments, you better use something other than IP to mark the vote, but if you still want to check if a particular IP has already voted use something like:…
-
2
votes4
answers1688
viewsA: Fill fields of a multidimensional array with null
Simply iterate on the elements and change their value if they are null: foreach($res as $key => $val) { if (empty($res[$key])) $res[$key] = null; }
-
9
votes4
answers817
viewsA: SQL Condition Array - PHP
Yes, you can use implode/Join, but your code is too repeatable, a simpler way to do this is: $keys = array('nome', 'tipoAnimal', 'raca', 'tamanho', 'sexo', 'estado', 'cidade'); $conditions =…
-
3
votes4
answers440
viewsA: Right menu in each Row of a table
You cannot use the same setting to set two different menus, you will have to create one for each different menu. This is because the contextmenu uses a selector to define which menu will be used,…
-
10
votes4
answers317
viewsA: Why are maps "faster" than arrays?
The idea is that the method indexOf will traverse each element of the array checking if the value corresponds, in which case the cost of this function is O(N) (see here about this notation). You can…
-
2
votes2
answers3954
viewsA: Two actions in the same form
Your code will do the POST for only one of the two Urls, and then it will be redirected to the page the form was sent to. See this example. When you use .submit() in js the browser will make the…