Skip to content

Instantly share code, notes, and snippets.

@inscapist
Created April 28, 2013 07:46
Show Gist options
  • Save inscapist/5476219 to your computer and use it in GitHub Desktop.
Save inscapist/5476219 to your computer and use it in GitHub Desktop.
template service
def design
@template = Template.find_or_create_by_name(params[:name])
end
def design_image
@template = Template.find_by_name(params[:name])
render layout: false
end
def save_design
template = Template.find_by_name(params[:name])
template.serialized = request.body
status = (template.save)? "success": "failed"
render json: {status: status, template: template.as_json}
end
def save_design_image
dir = "#{Rails.root}/public/cards"
File.open("#{dir}/#{params[:name]}.png","wb") do |file|
file.write(Base64.decode64(params[:png]))
end
render json: {status: 'success', resp: request.body}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment