I’m quite new to ruby and I’m learning with ruby on rails, but I have
hit a brick wall, because I want to parse several fields from a web
form which give the same data in a loop and maintaining the order from
the web form.
I can access the fields easily when the keynames are strings, but with
numbered keys params[:Data][1] doesn’t work. Also params[Data].each do
|data| leads to errors,
I would like to get a way of accessing the hashes inside data for
creating new database entries in rails.
I’m pretty sure that I’m not overidin rails in any way, I just have a
form temlate and I get the data from it by http post method and rails
parses the data into the params hash table.
I’m pretty sure that I’m not overidin rails in any way, I just have a
form temlate and I get the data from it by http post method and rails
parses the data into the params hash table.
But this will get me going forward
What I was thinking is if you shouldn’t use ActiveRecords to store the
data and let it sort out the data types - I smell lack of data model
definition / normalization a bit. Of course, if it’s not persitent data,
it’s not a good approach.
I can access the data with the :Data keys, but question remains, when I
have keys :1…:10 for example, how do I access them in a loop?
Hmm, this still seems strange, AFAIK, Rails sanitizes form input. Are
you
sure you aren’t circumventing what the Rails framework provides? A more
concise approach would be to let ActiveRecord do its magic if possible.
Anyhoo, you can still iterate over the data if for some strange reason
the
request parameter parser uses symbols like that as keys, e.g.:
for i in (1…10)
do_stuff_with(params[:Data][i.to_s.to_sym])
end
Anyways, more context wouldn’t hurt, but if the above does the trick,
fine
as well.
David V.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.