Macario Ortega wrote:
> The problem is that the Photos don't get saved in the database although
> they return false for #new_record? and Paperclip saves the files, if I
> set a debugger here:
>
> def create
> @page = Page.new(params[:page])
>
> if @page.save
> ...
> else
> debugger
> render :action => "new"
> end
> end
>
> and play with the irb:
>
>>> @planta.fotos.first
> => #<Photo id: 1, page_id: nil...
>>> @planta.fotos.first.new_record?
> => false
>>> Photo.count
> => 0
>>> Photo.find( 1 )
> => ActiveRecord::RecordNotFound Exception: Couldn't find Photo with ID=1
>>> @planta.fotos.first.save( false )
> => true
>>> Photo.count
> => 0
>
> This is most annoying and strange, it should be saved!!!
>
>
> In the log it appears as it has ben written to db:
> Photo Create (0.8ms) INSERT INTO "photos" ("updated_at"...
>
> Is there any kind of transaction or caching involved? Can I override
> this behavior?
Rails automatically wraps saves in transactions, but does not
reset the ids of successful saves within a rolled-back save,
even though those saves will themselves be rolled-back.
You'll have to do something like
@page.save_without_transactions
or save your photos outside the page save.
--
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---