Reputation: 63
I'm trying to create a simple sinatra app with one page containing a text area with a submit button underneath. Below that is another textarea that displays the modified text from the first textarea after the submit button is clicked.
Sinatra is new to me, so this is the best I can come up with so far:
CH.erb
<html>
<head>
<title>CH</title>
</head>
<body>
<div id="main">
<form action="" method="post">
<textarea id="orig" rows="25" cols="150"></textarea>
<br /><br /><br />
<button type="submit">Submit</button>
</form>
<br /><br /><br />
<textarea id="result" rows="25" cols="150"></textarea>
</div>
</body>
</html>
CH.rb
require 'sinatra'
get '/hi' do
erb :CH
end
post '/hi' do
# ????
end
Upvotes: 2
Views: 1017
Reputation: 303401
Use this for your response route:
post '/hi' do
@result = params['orig']
erb :CH
end
and modify your view like so:
<textarea id="result" rows="25" cols="150"><%=@result%></textarea>
I personally advocate Haml over Erb, but to each his/her own.
Upvotes: 3