In one of my Rails controllers, I'm trying to take Base64 encoding, decode it and write to a file (.png). Here is my code:
def create_character
@character = Character.new(params[:character])
@base64 = params[:base64]
File.open("app/assets/images/characters/#{@character.name.gsub(/\s+/, "")}-#{@character.author_name.gsub(/\s+/, "")}.png", 'wb') do |f|
f.write(Base64.decode64(@base64))
end
if @character.save
flash[:notice] = "Character created."
redirect_to(:action => 'share')
else
I get the following error:
undefined method `unpack' for #<ActiveSupport::HashWithIndifferentAccess:0x1044b22d8>
What's going on here?
Edit: One REALLY weird that the code to write the file works fine in the rails console, but not when the application starts.
source
share