A fake auction house I made for a school project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
the_auctionhouse/src/lib/func.rb

32 lines
723 B

3 years ago
def get_random_subtitle
subtitles = File.readlines "misc/subtitles.txt"
subtitles.sample.chomp
end
def is_logged_in
session[:userid] != nil
end
3 years ago
def get_current_user
session[:userid] && User.find_by_id(session[:userid])
end
# Serve templates
3 years ago
def serve(template, locals={}, layout: :layout)
3 years ago
locals[:session_user] = get_current_user unless !is_logged_in
# Serve the slim template
status session[:status] if session[:status]
session.delete :status
3 years ago
slim(template, locals: locals, :layout => layout)
end
3 years ago
# Save image
def save_image imgdata, path
image = Magick::Image.from_blob(imgdata).first
image.format = "PNG"
File.open(path, 'wb') do |f|
image.resize_to_fill(AVATAR_SIZE, AVATAR_SIZE).write(f)
3 years ago
end
end