I want to write something to a file.
# where userid is any intger [sic]
path = Rails.root + \"public/system/users/#{user.id}/style/img.jpg\"
File.open(path,
File.open(..., 'w') creates a file if it does not exist. Nobody promised it will create a directory tree for it.
Another thing, one should use File#join to build directory path, rather than dumb string concatenation.
path = File.join Rails.root, 'public', 'system', 'users', user.id.to_s, 'style'
FileUtils.mkdir_p(path) unless File.exist?(path)
File.open(File.join(path, 'img.jpg'), 'wb') do |file|
file.puts f.read
end