Hello,
Well I have a post and a post_picture model:
class Post < ActiveRecord::Base
has_one :post_picture
end
class PostPicture < ActiveRecord::Base
belongs_to :post
end
When a user creates a post he/she can upload a picture. So in the
create action on the posts_controller I have the following:
def create
@post = Post.new(params[:post])
@post_picture = PostPicture.new(:uploaded_data =>
params[:post_picture_file])
@post.post_picture = @post_picture
if @post.save
…
end
As you can see I relate the @post_picture with the @post using the
line of code
“@post.post_picture = @post_picture”
My question is:
When I do the @post.save does rails treats this as a transaction? (I
want to know because there is maybe possible data loss if the post is
saved into the posts table and the post_picture is not saved into the
post_pictures table or viceversa.
Thanks,
Elioncho