0

This was my first Sinatra project - link shortener but I am stuck with some errors and to be honest sinatra's built-in debugger tells me literally nothing. I would like you to give me a clue or suggest a solution to problem.

http://min.us/mkBIVTh7p - screenshot, this happen when I submit my form with url: http://google.com and word google

require 'sinatra'
    require 'shotgun'
    require 'data_mapper'
    require 'dm-migrations'
    require 'dm-sqlite-adapter'

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/form.db")

class Url
    include DataMapper::Resource
    property :id, Serial
    property :url, String
    property :suggestion, String
end

get '/' do 
    erb :index 
end

post '/' do
    Url.create(:url => params[:url], :suggestion=> params[:suggestion])
end

get '/Url.suggestion' do
    query = request_path.slice!(0) 
    redirection = Url.first(:suggestion => query)
    redirect redirection.url
end

index.rb

<!doctype html>
<html>
<head>
    <title>Skracanie linków</title>
</head>
<body>

<form name="form" method="post" action="#">
    <fieldset>
        <legend>Wpisz co trzeba</legend>
        <p><label> <input type="text" name="post[url]"/>Url:</label></p>
        <p><label> <input type="text" name="post[suggestion]"/>Suggested name:</label></p>
    </fieldset>
    <p class="center">
        <input type="reset" value="Wyczyść formularz"/>
        <input type="submit" value="Wyślij"/>
    </p>  

</form>
</body>
</html>
metrampaz
  • 641
  • 1
  • 6
  • 11
  • 2
    "stuck with some errors" -- show your errors. how else are we supposed to help you? you haven't even said what the problem is. – Ben Lee Apr 08 '12 at 12:41

1 Answers1

2

This is because you need to finalize your models. See http://datamapper.org/getting-started.html under the heading "Finalize Models".

Add the finalize command after defining your models:

class Url
    include DataMapper::Resource
    property :id, Serial
    property :url, String
    property :suggestion, String
end

# add this line
DataMapper.finalize
Ben Lee
  • 50,019
  • 12
  • 118
  • 142