Tuesday, November 24, 2015

Troubleshooting


require 'dm-core'
require 'dm-migrations'

DataMapper.setup(:default, 'sqlite3:recall.db')
# DataMapper.setup(:default, "ruby=C:/Ruby22-x64/bin/$(RUBY_BASE_NAME)")

class Scoop
include DataMapper::Resource
property :scoop_id, Serial
property :name, String
property :scoop, Text
property :scooped_on, Date
end
DataMapper.finalize

class Scooper
include DataMapper::Resource
property :scooper_id, Serial
property :scooper_name, String
property :scooper_email, Text
property :scooper_url, Date
end
DataMapper.finalize

Monday, November 23, 2015

Settings Variables

get '/root' do
settings.root
end

Passing Instance Variable to View

require 'sinatra'
get '/instance' do
@statement = "I am the coolest instance variable"
erb :insta
end
__END__
@@insta
<h1>He said "<%= @statement %>!"</h1>

Not Found

not_found do
erb :e404
end

params

require 'sinatra'

get '/:first/:second/:third' do
"first: #{params[:first]}, second: #{params[:second]}, third: #{params[:third]}"
end

Sunday, November 22, 2015

Hello World with a view

# create app2.rb with the following code:

require 'sinatra'

get '/' do

erb :templ

end

# create a sub folder named views, name it as templ.erb with following code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>External template</title>
</head>
<body>
<h1>Worked!</h1>
</body>
</html>

#run it. see it in browser....

Hello World with a template

#app1.rb
#----------------------

require 'sinatra'

get '/' do

erb :templ

end

__END__

@@templ

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World</title>
</head>
<body>
<h4> Hello World</h4>
</body>
</html>

# at command prompt, run it with ruby app1.rb
# See it on browser

Our First Sinatra App - Hello World

#Create a file named app.rb with the following code:

require 'sinatra'

get '/' do
 'Hello World'
end

#Thats it. You have a fully functional website powered by sinatra
# to run, type at command prompt:  ruby app.rb



# Now open your favorite browser and type at the address bar, http://localhost:4567





Installing Sinatra

Download Ruby 2.2.3 from http://rubyinstaller.org/downloads/
(Specific link: http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.3.exe)

Install it on windows 7

To check Ruby version go to command prompt [cmd]: type ruby -v

To see the gem version type at command prompt: gem -v 

To install Sinatra type at command prompt: gem install sinatra