模型:
after_save :set_correct_post_type
def set_correct_post_type
if self.document.present?
if (find_mime_type(self.document.original_filename) == "application/vnd.openxmlformats-officedocument.presentationml.presentation") || (find_mime_type(self.document.original_filename) == "application/vnd.ms-powerpoint")
self.update_attributes(:post_type => 3)
elsif (find_mime_type(self.document.original_filename) == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ) || (find_mime_type(self.document.original_filename) == "application/msword") || (find_mime_type(self.document.original_filename) == "application/pdf")
self.update_attributes(:post_type => 2)
elsif (MIME::Types.type_for(self.document.original_filename).first.content_type == "image/png") || (MIME::Types.type_for(self.document.original_filename).first.content_type =="image/jpeg") || (MIME::Types.type_for(self.document.original_filename).first.content_type == "image/jpg")
self.update_attributes(:post_type => 5)
end
end #line17
end
日志:
(0.3ms) rollback transaction
Completed 500 Internal Server Error in 1939ms (ActiveRecord: 37.5ms)
SystemStackError (stack level too deep):
app/models/teacher_post.rb:17:in `set_correct_post_type'
app/models/teacher_post.rb:17:in `set_correct_post_type'
app/models/teacher_post.rb:17:in `set_correct_post_type'
app/models/teacher_post.rb:17:in `set_correct_post_type'
app/models/teacher_post.rb:17:in `set_correct_post_type'
app/models/teacher_post.rb:17:in `set_correct_post_type'
app/models/teacher_post.rb:17:in `set_correct_post_type'
然后它一次又一次地重复最后一行,直到我手动停止它。谁能告诉我我做错了什么?