Answer the question
In order to leave comments, you need to log in
Saving data from client to server in Ruby?
Good afternoon!
I ask for advice or, perhaps, even an implementation example, if anyone has one.
The question is quite simple (and probably stupid), but I could not find an answer to it due to the dominance of Rails. No matter how I make a search query, I stumble upon manuals on ActiveRecord and its "friends".
Actually, my question is this: how to transfer data from the client (for example, values from the form filled in by the user) to the server, so that the server already saves the data in the database? Server without Rails but with Ruby.
In simple words: I have form.html with inputs and forms, I have calc.rb with a certain algorithm for calculating the received values and saving them in the database. How can I link these files?
I understand that the question is amateurish, I ask you to forgive me for this.
Thanks in advance for any help.
Answer the question
In order to leave comments, you need to log in
source 'https://rubygems.org'
gem 'rack'
gem 'sinatra'
#gem 'haml'
#gem 'sqlite3'
# config.ru (run with rackup)
require 'rubygems'
require 'bundler/setup'
Bundler.require
require './myapp.rb'
run Sinatra::Application
require 'sinatra'
get '/' do
erb :index # Отобразить форму по пути views/index.erb. Erb - это код HTML с вкраплениями кода на Ruby
end
post '/do_it'
"Thank you, #{params['name']}!"
end
<form action="/do_it" method="post">
<div>
<label for="name">Your Name:</label><br>
<input type="text" name="name"><br>
</div>
<button type="submit">Submit</button>
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question