[Nitro] Hash and field name
George Moschovitis
george.moschovitis at gmail.com
Wed Sep 21 03:48:04 EDT 2005
thanks Manolis, nice to see you contributing back to the project ;-)
regards,
George.
On 9/21/05, Emmanuel Piperakis <epiperak at softlab.ece.ntua.gr> wrote:
> On Wed, 21 Sep 2005, Emmanuel Piperakis wrote:
>
> >> <input name="testobj[key1]" ... />
> >> <input name="testobj[key2]" ... />
> > Sorry , I checked this and it did not work with fill. :-(
> > No worries though...
> >
> In order for hash to work:
> 1) In the model it has to be initialized (use symbols here , :en, :jp)
> class Bgroup
> property :title, Hash
> def initialize
> @title = Hash.new
> @title[:en] = @title[:jp] = nil
> end
> end
>
> 2) in the template use " and not ' for the name definition, and not
> symbols, just plain strings (populate @bgroup for edit case)
> <input id="bgroup_title[en]" name="title[en]" value=@bgroup.title[:en] />
> <input id="bgroup_title[jp]" name="title[jp]" value=@bgroup.title[:jp] />
> (the name="title[en]" is returned as "title" => {"en" => "inputed value",
> "jp" => "inputed other value" } )
>
> 3) in the controller manually assign the values. fill function does not
> work correctly with Hash, that is also why Date is not stored with fill
> (I guess...)
> def bgroup_save(meth = 'new')
> if request.post?
> if meth == 'new'
> bgroup = Bgroup.new
> elsif meth == 'update'
> oid = request['oid']
> bgroup = Bgroup[oid]
> end
> # request.fill(bgroup)
> bgroup.title[:en] = request['title']['en']
> bgroup.title[:jp] = request['title']['jp']
> bgroup.creation = Date.new(request['creation']['year'].to_i,
> request['creation']['month'].to_i-1,
> request['creation']['day'].to_i,
> Date::ITALY)
> bgroup.save
> end
> expire_output 'bgroups'
> redirect_to_referer
> end
>
> Sorry for the NOT ELEGANT solution, but until fill is updated to handle
> Hash better this will do.. ;-)
>
> Emmanouil Piperakis (epiperak at cs.ntua.gr)
> {To explore is Human, to Create is Devine,
> To teach is Primal, to Rule is Sin}
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>
--
http://www.gmosx.com
http://www.navel.gr
http://www.nitrohq.com
More information about the Nitro-general
mailing list