Bi1
(Bi ...)
18 February 2011 13:51
1
Hi,
I'm with the following code in html + javascript in my ruby application:
<script type="text/javascript">
$(document).ready(function(){
$('#numero_tarefas ').change(function(){
$('#tarefas ').html('');
for (var tarefa = 0; tarefa < $(this).val(); tarefa++) {
$('#tarefas ').append('Nome da tarefa ' + (tarefa + 1) + ': '
+ '<input type="text" id="tarefas['+ tarefa +'][input]" name="tarefas['+
tarefa +'][input]" /> ');
// copiando as opcoes das sub-tarefas modificando o id
$('[name=subtarefas-options] select').attr('id', tarefa);
$('#tarefas ').append('Número de subtarefas:'
+$('[name=subtarefas-options]').html() + '<br /><div
name="div-subtarefas" id="div-subtarefas"></div><br />');
// criacao dos inputs das subtarefas
$('[name=options_subtarefas]').change(function(){
// recuperar a primeira div
var first_subtarefa = $('#' + this.id + ' ~
[name=div-subtarefas]').first();
first_subtarefa.html('');
for (var sub_tarefa_id = 0; sub_tarefa_id < $(this).val();
sub_tarefa_id++) {
var t = parseInt(this.id ) + 1;
first_subtarefa.append(' Nome da
subtarefa '+ (sub_tarefa_id+1) + ' para a tarefa ' + (t) +
': ' +
<%#*'<input type="text" id="tarefas[' + this.id +
'][sub][' + sub_tarefa_id + ']" name="tarefas[' + this.id + '][sub][' +
sub_tarefa_id + ']" /><br />');%>
'<input type="text" id="tarefas[' + this.id + '][sub]['
+ sub_tarefa_id + ']" name="tarefas[' + this.id + '][sub][' +
sub_tarefa_id + ']" /><br />');
}
});
}
});
});
</script>
How can I take the array witch name is tarefas['+ tarefa +'][input] in
my controller using params?
···
--
Posted via http://www.ruby-forum.com/ .
Hi,
You can use:
params["+ tarefa +".to_sym][:input]
i guess.
···
2011/2/18 Bla ... <bianca.stephani@gmail.com>:
Hi,
I'm with the following code in html + javascript in my ruby application:
<script type="text/javascript">
$(document).ready(function(){
$('#numero_tarefas ').change(function(){
$('#tarefas ').html('');
for (var tarefa = 0; tarefa < $(this).val(); tarefa++) {
$('#tarefas ').append('Nome da tarefa ' + (tarefa + 1) + ': '
+ '<input type="text" id="tarefas['+ tarefa +'][input]" name="tarefas['+
tarefa +'][input]" /> ');
// copiando as opcoes das sub\-tarefas modificando o id
$\('\[name=subtarefas\-options\] select'\)\.attr\('id', tarefa\);
$\('\#tarefas'\)\.append\('Número de subtarefas:'
+$('[name=subtarefas-options]').html() + '<br /><div
name="div-subtarefas" id="div-subtarefas"></div><br />');
// criacao dos inputs das subtarefas
$\('\[name=options\_subtarefas\]'\)\.change\(function\(\)\{
// recuperar a primeira div
var first\_subtarefa = $\('\#' \+ this\.id \+ ' \~
[name=div-subtarefas]').first();
first_subtarefa.html('');
for (var sub_tarefa_id = 0; sub_tarefa_id < $(this).val();
sub_tarefa_id++) {
var t = parseInt(this.id) + 1;
first_subtarefa.append(' Nome da
subtarefa '+ (sub_tarefa_id+1) + ' para a tarefa ' + (t) +
': ' +
<%#*'<input type="text" id="tarefas[' + this.id +
'][sub][' + sub_tarefa_id + ']" name="tarefas[' + this.id + '][sub][' +
sub_tarefa_id + ']" /><br />');%>
'<input type="text" id="tarefas[' + this.id + '][sub]['
+ sub_tarefa_id + ']" name="tarefas[' + this.id + '][sub][' +
sub_tarefa_id + ']" /><br />');
}
});
}
});
});
</script>
How can I take the array witch name is tarefas['+ tarefa +'][input] in
my controller using params?
--
Posted via http://www.ruby-forum.com/\ .
Bla ... wrote in post #982469:
How can I take the array witch name is tarefas['+ tarefa +'][input] in
my controller using params?
You can use <input type="hidden"> to put any extra variables you want
into the FORM, then you can POST them, then you'll usually get a params
object in your Ruby controller.
But since you don't show your full HTML I can't be sure you're building
a FORM, and you don't show any ruby code nor say which ruby framework
you're using, it's hard to be more specific.
It would be much better if you could build a simple, minimal and
complete example which demonstrates your problem.
···
--
Posted via http://www.ruby-forum.com/\ .
Bi1
(Bi ...)
21 February 2011 12:33
4
params["+ tarefa +".to_sym][:input] doesn't works.
···
--
Posted via http://www.ruby-forum.com/ .
Bi1
(Bi ...)
21 February 2011 14:22
6
getting this:
[4;36;1mSQL (1.3ms)[0m [0;1mINSERT INTO "nome_tarefas_fluxos"
("fluxo_id", "nome_tarefa", "numero_subtarefas") VALUES(110,
E'0sub0ccccccccccinputcccccccccc', NULL) RETURNING "id"[0m
in this:
Parameters: {"x"=>"12", "numero_tarefas"=>"1", "y"=>"11",
"action"=>"create",
"authenticity_token"=>"id8C+Wlqc90ryf4479bFISkyCmLhgxr+h8n7A8osLlY=",
"tarefas"=>{"0"=>{"sub"=>{"0"=>"cccccccccc"}, "input"=>"cccccccccc"}},
"options_subtarefas"=>"Selecione quantidades...",
"controller"=>"fluxos", "fluxo"=>{"nome"=>"ccccccccccc"}}
[4;35;1mPermissao Load (2.5ms)[0m [0mSELECT * FROM "permissoes"
WHERE (usuario_id = 2 AND perfil = E'Avançado' AND projeto_id = 0) [0m
[4;36;1mSQL (0.3ms)[0m [0;1mBEGIN[0m
[4;35;1mSQL (1.2ms)[0m [0mINSERT INTO "fluxos" ("created_at",
"nome", "numero_tarefas", "updated_at", "numero_subtarefas")
VALUES('2011-02-21 11:20:06.285885', E'ccccccccccc', 1, '2011-02-21
11:20:06.285885', NULL) RETURNING "id"[0m
[4;36;1mSQL (7.1ms)[0m [0;1mCOMMIT[0m
[4;35;1mSQL (0.3ms)[0m [0mBEGIN[0m
[4;36;1mSQL (1.3ms)[0m [0;1mINSERT INTO "nome_tarefas_fluxos"
("fluxo_id", "nome_tarefa", "numero_subtarefas") VALUES(110,
E'0sub0ccccccccccinputcccccccccc', NULL) RETURNING "id"[0m
[4;35;1mSQL (11.0ms)[0m [0mCOMMIT[0m
Redirected to http://localhost:3001/fluxos
Completed in 61ms (DB: 25) | 302 Found [http://localhost/fluxos ]
···
--
Posted via http://www.ruby-forum.com/ .
Bi1
(Bi ...)
21 February 2011 14:48
7
i get this:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
···
--
Posted via http://www.ruby-forum.com/ .
What parameters do You get in your server log?
There should be something like:
Started POST "/session/" for 127.0.0.1 at Mon Feb 21 09:46:30 +0100 2011
Processing by SessionController#create as HTML
Parameters: {"name"=>"admin", "commit"=>"logowanie",
"authenticity_token"=>"[FILTERED]", "utf8"=>"✓",
"password"=>"[FILTERED]"}
···
2011/2/21 Bla ... <bianca.stephani@gmail.com>:
nether params[:tarefas]
--
Posted via http://www.ruby-forum.com/\ .
So, You have array 'terefas'. You can get that two values "cccccccccc" this way:
params[:terefas][0][:sub][0]
and
params[:terefas][0][:input]
as You can see it there:
tarefas"=>{"0"=>{"sub"=>{"0"=>"cccccccccc"}, "input"=>"cccccccccc"}}
···
2011/2/21 Bla ... <bianca.stephani@gmail.com>:
getting this:
[4;36;1mSQL (1.3ms)[0m [0;1mINSERT INTO "nome_tarefas_fluxos"
("fluxo_id", "nome_tarefa", "numero_subtarefas") VALUES(110,
E'0sub0ccccccccccinputcccccccccc', NULL) RETURNING "id"[0m
in this:
Parameters: {"x"=>"12", "numero_tarefas"=>"1", "y"=>"11",
"action"=>"create",
"authenticity_token"=>"id8C+Wlqc90ryf4479bFISkyCmLhgxr+h8n7A8osLlY=",
"tarefas"=>{"0"=>{"sub"=>{"0"=>"cccccccccc"}, "input"=>"cccccccccc"}},
"options_subtarefas"=>"Selecione quantidades...",
"controller"=>"fluxos", "fluxo"=>{"nome"=>"ccccccccccc"}}
[4;35;1mPermissao Load (2.5ms)[0m [0mSELECT * FROM "permissoes"
WHERE (usuario_id = 2 AND perfil = E'Avançado' AND projeto_id = 0) [0m
[4;36;1mSQL (0.3ms)[0m [0;1mBEGIN[0m
[4;35;1mSQL (1.2ms)[0m [0mINSERT INTO "fluxos" ("created_at",
"nome", "numero_tarefas", "updated_at", "numero_subtarefas")
VALUES('2011-02-21 11:20:06.285885', E'ccccccccccc', 1, '2011-02-21
11:20:06.285885', NULL) RETURNING "id"[0m
[4;36;1mSQL (7.1ms)[0m [0;1mCOMMIT[0m
[4;35;1mSQL (0.3ms)[0m [0mBEGIN[0m
[4;36;1mSQL (1.3ms)[0m [0;1mINSERT INTO "nome_tarefas_fluxos"
("fluxo_id", "nome_tarefa", "numero_subtarefas") VALUES(110,
E'0sub0ccccccccccinputcccccccccc', NULL) RETURNING "id"[0m
[4;35;1mSQL (11.0ms)[0m [0mCOMMIT[0m
Redirected to http://localhost:3001/fluxos
Completed in 61ms (DB: 25) | 302 Found [http://localhost/fluxos\ ]
--
Posted via http://www.ruby-forum.com/\ .
Paste here code where You're trying to get that value, please.
···
2011/2/21 Bla ... <bianca.stephani@gmail.com>:
i get this:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.
--
Posted via http://www.ruby-forum.com/\ .
If this doesn't work, try
params["tarefas"]["0"]["sub"]["0"]
and
params["tarefas"]["0"]["input"]
···
On Mon, Feb 21, 2011 at 8:40 AM, blazeroot <blazeroot@gmail.com> wrote:
So, You have array 'terefas'. You can get that two values "cccccccccc" this
way:
params[:terefas][0][:sub][0]
and
params[:terefas][0][:input]
as You can see it there:
tarefas"=>{"0"=>{"sub"=>{"0"=>"cccccccccc"}, "input"=>"cccccccccc"}}
Bi1
(Bi ...)
22 February 2011 13:40
12
params["tarefas"]["0"]["input"] works perfectly...
now... i'm whit a while to take all the names... how can I take the
number of "subtarefas" knowing that the html is like this:
<select id="numero_tarefas" name="numero_tarefas">
<option>Selecione quantidades...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
</select>
<div id='tarefas'></div>
<div name="subtarefas-options" style="display:none;">
<select id="options_subtarefas" name="options_subtarefas">
<option>Selecione quantidades...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</div>
I want to take the number selected in "options_subtarefas" for each
"tarefa" that I toke the "input".
···
--
Posted via http://www.ruby-forum.com/ .