Topic: Accessing Parameters

Hi,

having a bit of trouble, sure it's pretty easy, but I want to be able to access a param, and everything I try is not working

Parameters: {"commit"=>"Create", "owner_pictures"=>{"0"=>{"notes"=>"test1", "tmp_file"=>#<File:/tmp/CGI1702.31>}, "1"=>{"notes"=>"test2", "tmp_file"=>#<File:/tmp/CGI1702.33>}}

I'm trying to get a handle on [owner_pictures][0][tmp_file] and the other params, but individually, as I need to process them before they get saved to the database

I've been trying just to do the [0] based one from the above, like this

params[:owner_pictures][0]['tmp_file'].read

I've moved the [0] around and tried all sorts of combinations for a couple of days, I'm lost

Can anyone help

thanks

Re: Accessing Parameters

Try placing the zero in a string:

params[:owner_pictures]['0']['tmp_file']

Railscasts - Free Ruby on Rails Screencasts

Re: Accessing Parameters

doh, that's not even funny

that's getting me past that line, but now I run into something else that looks related

my controller code

@params['owner_pictures']['picture'] = params[:owner_pictures]['0']['tmp_file'].read
   
@params['owner_pictures']['thumbnail'] = create_thumb(@params['owner_pictures']['picture'])
@params['owner_pictures'].delete('tmp_file')   

@owner_picture = OwnerPicture.new(@params['owner_pictures'])

(I can't find how to do that fancy code thing you do)

this now errors on the 4th line with

undefined method `0=' for #<OwnerPicture:0x265bb60>

any idea?

Re: Accessing Parameters

Actually, I've solved it, by deleting the '0' as well

@params['owner_pictures']['picture'] = params[:owner_pictures]['0']['tmp_file'].read
@params['owner_pictures']['thumbnail'] = create_thumb(@params['owner_pictures']['picture'])
@params['owner_pictures'].delete('tmp_file')   
@params['owner_pictures'].delete('0')


Thanks for the help, now to work out how to do it in a loop