0

I understand how to generate objects from the database, using Sinatra with formatting, and I understand from tutorials how to use POST to send information back, but I don't understand how to use POST to transfer information from the browser (for instance from a text field, or inside <p id="stufftotransfer"><%= @stuff.each do || stuff.name %></p>) back to the database and store it to show it's working.

Basically in Sinatra, if you want to display something as output you do something like this ->

application_controller.rb

get '/items' do
  erb :items #for example
end

#Actually this is items.erb for instance. I can't get .erb to pass format check
<html> <% @items.each do | item | %> <div class="itemContainer"> <p><%= h item.name %></p>]
<p><%= h item.price %></p> <p><%= h item.id %></p> <p><%= h item.description %> </p> <a href="/addItem" class="itemContainer-link productItem btn btn-
primary">Add to Cart</a> <% end %> </html>

From there: adding the item to an element of a document generated by another .erb (inside itemList)
2) sending it back via 'POST'

itemcontroller.rb

post '/addItem' do
   erb :itemlist #Template that will store the value in a <p>,etc
end

post '/backtodatabase' do
   #? Grab value off element of .erb send it back and store in a table
end

Edited by Mrewan79

2
Contributors
1
Reply
13
Views
2 Months
Discussion Span
Last Post by cereal
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.