On May 18, 2016 at 03:17:10, Colin Law ([email protected]) wrote:

On 18 May 2016 at 08:51, Alessio Varalta <[email protected]> wrote: 
> Hi, if I try params.inspect i see 
> 
> {"utf8"=>"✓", 
> 
> "authenticity_token"=>"RvpwQw/RdTAT2d4jtaSyBAYRgT1mKgWg9kyrS7pUnMo=", 
> "person"=>{"birthplace"=>{"it"=>"Padova", "de"=>"Padovan"}}, 
> "commit"=>"Create Person", "action"=>"create", "controller"=>"people"} 
> 
> 
> So I think is correct but in database i have 
> 
> --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nit: Padova\nde: 
> Padovan\n 

I have just realised what you are trying to do. Are you trying to 
save a hash object in a field in the database? I have never done that 
as almost always you are better to use models and associations for 
storing the data. That is the Rails way. If you really need to do 
that then google for how to save a hash in the database using rails, 
for how to use serialisers to do it. 

Colin 


Postgresql 9.2 has JSON objects, 9.4 introduces JSONB, but they are often more 
hassle than they are worth. See the Postgresql docs.

ActiveRecord can also serialize/deserialze hashs (or any other sort of Ruby 
non-primitive), but it's also often more hassle than it's worth. See 
http://api.rubyonrails.org/classes/ActiveRecord/AttributeMethods/Serialization/ClassMethods.html#method-i-serialize
 for the latter. 

I'll very much second Colin's first point: more analysis and better 
understanding of the data structures generally give better results. (i.e., more 
testable, extendable, maintainable, to my mind)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/etPan.573c6ba7.1eedd42d.d33b%40pontiki2.local.
For more options, visit https://groups.google.com/d/optout.

Reply via email to