Is it because I don’t have a file field in my database? The database
keeps the name of the file and some information related to it. I want
to save the file locally only, not to the database.
You’re tring to access the ‘logfile_fileName’ key of params, but
params only has a ‘logfile’ and a ‘commit’ key. But, the param
‘logfile’ is itself a hash, with a key ‘fileName’, so what you really
want is:
@logfile.file= params[‘logfile’][‘fileName’]
When you have an underscore in the param name, Rails groups the params
by prefix. Here, the prefix is ‘logfile’, so you get a hash saved
under ‘logfile’ with all the params which start ‘logfile_’, rather
than accessing the params ‘logfile’ itself.
This is especially useful when, say, you want to create two model
objects, and you want to initialise them from a hash. This way you can
have fileds ‘alpha_name’, ‘alpha_address’ and ‘beta_name’ and
‘beta_age’, which will give you two hashes, params[‘alpha’] and
params[‘beta’]. Have a look in the documentation under form helpers to
learn more about how this works.
Everyone in the Ruby community has been so helpful.
I have to admit this is scaffold withdrawal, but I honestly tried to
read the documentation (I just didn’t know where to start). Much of it
is still magic and mystics to me, but I hope to become better at it.