I am trying to retrieve data from a PostgreSQL database with Sequel in Sinatra.
DB = Sequel.connect('postgres://connection_data')
items = DB[:items]
Then I try to get an entry with a specific ID:
get '/:id' do
@item = items.filter(:id => params[:id])
erb :edit
end
In my edit view I would like to display the content of the @item variable. The problem is that I don´t know how to get for example the ID.
<% if @item %>
<a href="/<%= @item.id %>/doit">Do something</a>
<% else %>
<p>Item not found.</p>
<% end %>
I tried using @item.id and @item[:id] but both don´t work. I get an error undefined method 'id' for #<Sequel::Postgres::Dataset:0x007fac118b7120>
. What would be the right way to retrieve the values from the @item variable?