Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby with Sequel and Sinatra: form parameter passing
    primarykey
    data
    text
    <p>I am new to Ruby and Sinatra. I am attempting to pass parameters from an HTML form and insert them into a PostgreSQL database (on Heroku) with Sequel. </p> <p>The connection to the database works because I have succeeded with this code block</p> <pre><code>DB = Sequel.connect(connection_ credentials) insert_ds = DB["INSERT INTO users (email_address, username, password) VALUES ('email@email.com', 'my_username', 'my_password')"] insert_ds.insert </code></pre> <p>This works fine, but I cannot insert data from an HTML form. The data is not being passed. </p> <p>So, for example, this does not work</p> <pre><code>@email_address = params[:email_address] @username = params[:username] @password = params[:password] insert_ds = DB["INSERT INTO users (email_address, username, password) VALUES (@email_address, @username', @password)"] insert_ds.insert </code></pre> <p>The error message is</p> <blockquote> <p>Sequel::DatabaseError at / PG::Error: ERROR: column "email_address" does not exist LINE 1: ...sers (email_address, username, password) VALUES (@email_addr... ^ </p> </blockquote> <p>which leads me to presume that the parameter was not passed</p> <p>The full code is:</p> <pre><code>require 'sinatra' require "rubygems" require "sequel" require 'sinatra/sequel' require 'pg' DB = Sequel.connect('postgres://my username:my password@ec2-54-243-250-125.compute-1.amazonaws.com:5432/d70h0792oqobc') get '/' do #@users = users.all :order =&gt; :id.desc #@title = 'All Users' erb :index end post '/' do @email_address = params[:email_address] @username = params[:username] @password = params[:password] insert_ds = DB["INSERT INTO users (email_address, username, password) VALUES (@email_address, @username, @password)"] insert_ds.insert redirect '/' end __END__ @@ layout &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;&lt;/head&gt; &lt;body&gt; &lt;%= yield %&gt; &lt;/body&gt; &lt;/html&gt; @@index &lt;section id="add"&gt; &lt;form action="/" method="post"&gt; &lt;label class="label"&gt; &lt;span&gt;Email Address: &lt;/span&gt; &lt;/label&gt; &lt;input type="text" id="email_address" name="email_address" /&gt; &lt;label class="label"&gt; &lt;span&gt;Username: &lt;/span&gt; &lt;/label&gt; &lt;input type="text" id="username" name="username" /&gt; &lt;label class="label"&gt; &lt;span&gt;Password: &lt;/span&gt; &lt;/label&gt; &lt;input type="password" id="password" name="password" /&gt; &lt;input type="submit" value="Register me!"&gt; &lt;/form&gt; &lt;/section&gt; </code></pre> <p>Very grateful for all help!</p> <p>Thank you. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload