Posts Tagged ‘crystal’
Kemal routing redirecting a subtree
This code snippet shows you how to redirect an entire subtree and remove the first part of the subtree. This might come in useful, for example when you have outside links referencing different languages (e.g. /de /fr /it) and content paths in them, and you want to serve everything from the same endpoints. Crystal Lang…
WeiterlesenDealing with NIL in JSON::Any in Crystal Lang
One of the challenges when developing with Crystal is that it is not as forgiving about data types as, say, Python or Ruby. nil will keep you occupied. The following error message: cast from Nil to String failed, at /usr/share/crystal/src/json/any.cr:220:5:220 can be solved by: # cast to string, THEN check if it is nil if…
WeiterlesenGetting POST requests to work with Axios, Kemal (crystal lang), vue.js
In picockpit.com, I am using AJAX requests to communicate with the backend for update operations. For instance, if you want to change the name of this Pi, you would select: which shows an inline form: how to show this inline form with vue.js is besides the point of this post (even though very interesting!) Clicking…
Weiterlesenmongo_orm custom name for collection
mongo_orm will automatically determine the name for your collection by using the Module and Class name, and appending an “s”. In cases where you want to name your collection, you can simply do this: class PapiTest < Mongo::ORM::Document collection_name “Buster” field test : String end get “/” do pt = PapiTest.new pt.test = “I want…
WeiterlesenInstructions for adding a user to a mongo database for mongo_orm
You don’t want your web application to access the database using your database admin user. Additionally you want it to access only one specific database – maybe you have additional databases running in your mongo instance. Prerequisites: mongo_orm expects the database configuration as environment variables or as a file config/database.yml in your project. The config/database.yml…
WeiterlesenBuilding a persistent in-line editing experience with Crystal, MongoDB (datanoise / sam0x17)
As documentation is still sparse, I would like to add some. This is what I am building currently: The individual fields are going to be editable with an inline editor, which will automatically save to the backend – no need for reloading the whole page. The point of the whole is a backend for my…
WeiterlesenUsing modules in crystal
As your application grows, you would like to move from one big .cr file to separating your code into smaller files. You can use require from your main .cr file to add code from other files: require “./tools/*” This statement will add code from the tools directory, relative to your main .cr file. This will…
WeiterlesenThe scope of ecr within crystal: or how do I pass in variables and Objects into ECR templates?
As a beginner in the Crystal language I still struggle to get my head around some of the concepts in it, and develop a feel for coding in Crystal. When I come across difficult problems, which I solve or start to understand, I blog about them, so others can benefit – as lack of documentation…
WeiterlesenInstall Crystal on Docker: how to add the Crystal repository to Docker in the Dockerfile
Dockerfile (excerpt) ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn RUN apt-get update && apt-get install -y \ software-properties-common \ build-essential \ libevent-dev \ libssl-dev \ libxml2-dev \ libyaml-dev \ libgmp-dev \ libreadline-dev \ apt-transport-https \ iputils-ping \ git \ aptitude \ nano \ openssh-server \ && apt-key adv –keyserver keys.gnupg.net –recv-keys 09617FD37CC06B54 \ && add-apt-repository ‘deb https://dist.crystal-lang.org/apt crystal…
WeiterlesenCrystal & Alpine on the Raspberry Pi
Bringing together two interesting technologies: Alpine Linux – a small-size and security oriented Linux distribution Crystal – a compiled language with a nice syntax (similar to Ruby) on the Raspberry Pi (armhf / ARMv6, which would also support the Pi Zero W) is not possible currently, as of 21.12.2018. There is no (at least no…
Weiterlesen