Whoops!

Son of a gun! I had tried

  params[:photo][:project_id]

earlier, and it failed. I was testing for

if @photo.mainimg_file_name != nil

at that point, which raised an error. I did not test after switching
to

   if @photo != nil

Which I tried once more, and it indeed does work.
Thank you very, very, very much!

Cheers,

   Jet


On Sep 17, 12:30 pm, kevinpfromnm <[email protected]> wrote:
> >   �...@photo = Photo.find_by_project_id(params[:photo => :project_id])
> >                               (also have tried (params[:photo]
> > [:project_id]
>
> I'd be surprised if this didn't give an exception as the params is
> using hash notation for the key.  If project_is is unique on your
> photo, then you want something like params[:photo][:project_id]
> assuming your params data structure is something like this:
>
> { :photo => { :project_id => #, ... }, ... }
>
> Do a raise params.inspect at the beginning of your controller method
> if you're not sure how it is structured.  Looking further down, that
> is indeed how your params is handled.
>
> You might want to take a look at some ruby tutorials and practice with
> that or if it's just the hashes throwing you off, take a closer look
> at them.
>
>
>
> > in PhotosController statement always evalutates to nil,
>
> >    if @photo != nil
> >         @photo.update_attributes(params[:photo])
>
> > even though the project_id is in the params hash:
> >    (output from my application log:)
>
> >  Parameters: {"photo"=>{"project_id"=>"371", "user_id"=>"14",
> > "lwrimg"=>#<File:/tmp/RackMultipart.26504.0>}, "page_path"=>"projects/
> > edit", "authenticity_token"=>"iiwoOHgAaBTCv/U4xhmvlR2qleLbG
> > +Ov70cubJ7G8jQ=", "after_submit"=>"stay-here"}
>
> > ...so the project_id is set.
>
> > However, the SQL query is:
>
> >     [4;35;1mPhoto Load (0.2ms)[0m   [0mSELECT * FROM `photos` WHERE
> > (`photos`.`project_id` IS NULL) LIMIT 1[0m
>
> > ...which seems to indicate that (params[:photo => :project_id]) is
> > returning NULL,
> > or that I am misunderstanding
>
> > @photo = Photo.find_by_project_id(params[:photo => :project_id])
>
> > I thought the above would be that @photo is a copy of the record found
> > in the d.b., and
> > thus I would be able to use the test:
>
> >  if @photo != nil
>
> > So, what is the correct way to update a record if it exists?
>
> > Cheers,
> >    Jet
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to