As we support many blockchain events, that was obvious for us to share this article about creating an app using blockchain plus our core stack framework – Rails. This tutorial shows how to work with blockchain using Ruby and how to create a decentralized application based on Ruby on Rails. It doesn’t cover deep knowledge of blockchain, only a basic introduction that helps to understand how it works and how to design dApp architecture.
In a standard case, the main part is a server which holds the code of the app and connects to a database which stores all necessary information. In a decentralized app, we don’t have server side because we don’t want to store any data on unsafe servers. The code is stored in a blockchain and users connect directly to it via UI, so all actions, like creating and signing transaction should be executed client side.
The administrator should be able to create voting, choose which users could vote and meal types to vote for. Users can only vote (once) and see results. Each user is obliged to have an account on blockchain (a wallet).
To create the application:
- Start coding in Ruby
- Create two models of application: User and Voting
- Create a blockchain transaction and sign it with a private key (the user which makes a transaction).
- Deploy the contract on the blockchain
That’s it! You created a simple voting application using ruby on rails and blockchain. It’s fine, works and looks good, but can be not perfect and not following the blockchain good practices. But It is an easier way than using the command line especially when you need to parametrize each contract and the person who does it is not a very technical one.
Find more materials about Rails on our blog and for more code details, please read this article by Kuba Wilczek.